{ "version": 3, "sources": ["event_day_of_banner_controller-dbb17119.js"], "sourcesContent": ["import { Controller } from \"@hotwired/stimulus\"\nimport TimeAgo from \"javascript-time-ago\"\nimport en from \"javascript-time-ago/locale/en\"\n\nexport default class extends Controller {\n static targets = [ \"text\", \"icon\" ]\n static classes = [ \"now\", \"soonIcon\", \"nowIcon\" ]\n\n static values = {\n startDate: String,\n imminentDate: String,\n beforeStartText: String,\n imminentText: String,\n afterStartText: String\n }\n\n initialize() {\n TimeAgo.addDefaultLocale(en)\n this.timeAgo = new TimeAgo()\n this.currentText = null\n }\n\n connect() {\n this.updateMode()\n this.updateText()\n this.updatePeriodically()\n }\n\n disconnect() {\n this.stopPeriodicUpdates()\n }\n\n transitionToNowMode() {\n if (!this.element.classList.contains(this.nowClass)) {\n this.element.classList.add(this.nowClass)\n }\n\n if (this.iconTarget.classList.contains(this.soonIconClass)) {\n this.iconTarget.classList.remove(this.soonIconClass)\n }\n\n if (!this.iconTarget.classList.contains(this.nowIconClass)) {\n this.iconTarget.classList.add(this.nowIconClass)\n }\n }\n\n imminentDateValueChanged() {\n this.imminentDate = new Date(this.imminentDateValue)\n }\n\n startDateValueChanged() {\n this.eventStartDate = new Date(this.startDateValue)\n }\n\n checkImminentDatePassed() {\n const currentTime = new Date()\n return (currentTime >= this.imminentDate)\n }\n\n checkStartDatePassed() {\n const currentTime = new Date()\n return (currentTime >= this.eventStartDate)\n }\n\n getTemplateText() {\n const imminentDatePassed = this.checkImminentDatePassed()\n const startDatePassed = this.checkStartDatePassed()\n\n if (imminentDatePassed && !startDatePassed) {\n return this.imminentTextValue\n } else if (startDatePassed) {\n return this.afterStartTextValue\n }\n\n return this.beforeStartTextValue\n }\n\n interpolateRelativeTimeInTemplateText(interpolation) {\n const templateText = this.getTemplateText()\n return templateText.replace(\"%{relativeTime}\", interpolation)\n }\n\n changeText(newText) {\n this.currentText = newText\n this.textTarget.textContent = newText\n }\n\n updateText() {\n const relativeTime = this.getReformattedDateInRelativeTime()\n const newText = this.interpolateRelativeTimeInTemplateText(relativeTime)\n \n if (this.currentText !== newText) {\n this.changeText(newText)\n }\n }\n\n getReformattedDateInRelativeTime() {\n const baseString = this.timeAgo.format(this.eventStartDate)\n return baseString.replace(\"in\", \"in about\")\n }\n\n updateMode() {\n const imminentDatePassed = this.checkImminentDatePassed()\n\n if (imminentDatePassed) {\n this.transitionToNowMode()\n }\n }\n\n refresh() {\n this.updateMode()\n this.updateText()\n this.stopUpdatesIfAppropriate()\n }\n\n stopUpdatesIfAppropriate() {\n const startDatePassed = this.checkStartDatePassed()\n\n if (startDatePassed) {\n this.stopPeriodicUpdates()\n }\n }\n\n updatePeriodically() {\n const refreshRateInMs = 5000\n\n this.refresher = setInterval(() => {\n this.refresh()\n }, refreshRateInMs)\n }\n\n stopPeriodicUpdates() {\n if (this.refresher) {\n clearInterval(this.refresher)\n }\n }\n}\n"], "mappings": "wKAAA,gDACA,mCACA,6CAEA,qBAAO,SAAsB,EAAW,CAYtC,YAAa,CACX,EAAQ,iBAAiB,CAAE,EAC3B,KAAK,QAAU,GAAI,GACnB,KAAK,YAAc,IACrB,CAEA,SAAU,CACR,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,mBAAmB,CAC1B,CAEA,YAAa,CACX,KAAK,oBAAoB,CAC3B,CAEA,qBAAsB,CACpB,AAAK,KAAK,QAAQ,UAAU,SAAS,KAAK,QAAQ,GAChD,KAAK,QAAQ,UAAU,IAAI,KAAK,QAAQ,EAGtC,KAAK,WAAW,UAAU,SAAS,KAAK,aAAa,GACvD,KAAK,WAAW,UAAU,OAAO,KAAK,aAAa,EAGhD,KAAK,WAAW,UAAU,SAAS,KAAK,YAAY,GACvD,KAAK,WAAW,UAAU,IAAI,KAAK,YAAY,CAEnD,CAEA,0BAA2B,CACzB,KAAK,aAAe,GAAI,MAAK,KAAK,iBAAiB,CACrD,CAEA,uBAAwB,CACtB,KAAK,eAAiB,GAAI,MAAK,KAAK,cAAc,CACpD,CAEA,yBAA0B,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