{"version":3,"sources":["webpack:///./src/js/modules/ms-counter.ts"],"names":["Module","this","numbers","el","querySelectorAll","Date","dataset","deadline","Math","remainingTime","getRemainingTime","minutes","pad","hours","days","requestAnimationFrame","showTime","bind","Component"],"mappings":"glDAEMA,E,yZACJ,WACEC,KAAA,IAAW,CACTC,QAASD,KAAKE,GAAGC,iBAAiB,gCAGpCH,KAAA,SAAgB,IAAII,KAAKJ,KAAKE,GAAGG,QAAjB,WAAhB,UACAL,KAAA,a,8BAGF,YAEE,OAAOM,GADa,IAAIF,MAAxB,Y,iBAIF,YACE,MAAO,WAAIG,WAAJ,WAAP,K,sBAGF,WACE,IAAMC,EAAgBR,KAAKS,iBAAiBT,KAA5C,UACA,KAAmB,CACjB,IAAMU,EAAUV,KAAKW,IAClBH,EAAgB,IAAjB,OAEKA,EAAgB,IAHvB,IAKMI,EAAQZ,KAAKW,IAChBH,EAAgB,KAAjB,OAEKA,EAAgB,KAHvB,IAKIK,EACFL,EAAgB,MAAhBA,IAEIA,EAAgB,MAGpBK,EADEA,EAAJ,IACEA,MACSA,EAAJ,IACEN,WAAPM,GAEOb,KAAKW,IAAZE,GAGFb,KAAA,2BACAA,KAAA,2BACAA,KAAA,yBA1BiB,EA6BbQ,GAAJ,KACEM,sBAAsBd,KAAKe,SAASC,KAApCF,a,iFAnDaG,aAyDrB","file":"92.bundle.js?v=c443596aa450c418ae17","sourcesContent":["import { Component } from '@verndale/core';\n\nclass Module extends Component {\n setupDefaults() {\n this.dom = {\n numbers: this.el.querySelectorAll('.ms-event-countdown__number')\n };\n\n this.deadline = new Date(this.el.dataset.eventDate).getTime();\n this.showTime();\n }\n\n getRemainingTime(deadline: number) {\n const currentTime = new Date().getTime();\n return deadline - currentTime;\n }\n\n pad(value: number) {\n return `0${Math.floor(value)}`.slice(-2);\n }\n\n showTime() {\n const remainingTime = this.getRemainingTime(this.deadline);\n if (remainingTime) {\n const minutes = this.pad(\n (remainingTime / (60 * 1000)) % 60 < 0\n ? 0\n : (remainingTime / (60 * 1000)) % 60\n );\n const hours = this.pad(\n (remainingTime / (60 * 60 * 1000)) % 24 < 0\n ? 0\n : (remainingTime / (60 * 60 * 1000)) % 24\n );\n let days: number | string =\n remainingTime / (24 * 60 * 60 * 1000) < 0\n ? 0\n : remainingTime / (24 * 60 * 60 * 1000);\n\n if (days > 999) {\n days = '999';\n } else if (days > 100) {\n days = Math.floor(days);\n } else {\n days = this.pad(days);\n }\n\n this.dom.numbers[0].innerText = days;\n this.dom.numbers[1].innerText = hours;\n this.dom.numbers[2].innerText = minutes;\n\n // ensure clock only updates if a second or more is remaining\n if (remainingTime >= 1000) {\n requestAnimationFrame(this.showTime.bind(this));\n }\n }\n }\n}\n\nexport default Module;\n"],"sourceRoot":""}