{"version":3,"file":"delivery_controller-DmeL1YPB.js","sources":["../../../app/javascript/controllers/campaign/delivery_controller.js"],"sourcesContent":["import ApplicationController from \"../application_controller\"\n\nexport default class extends ApplicationController {\n static targets = [\"submitButton\", \"date\", \"hour\", \"scheduleDatePicker\", \"nightHoursConflict\"]\n static values = {\n scheduledLabel: String,\n sendNowLabel: String,\n nightHoursConfigured: { type: Boolean, default: false },\n nightHoursStart: String,\n nightHoursEnd: String,\n hour: String,\n }\n\n initialize() {\n this.showSendNowLabel()\n }\n\n showSendNowLabel() {\n this.submitButtonTarget.innerText = this.sendNowLabelValue\n }\n\n showScheduledLabel() {\n this.submitButtonTarget.innerText = this.scheduledLabelValue\n }\n\n enableSubmitButton() {\n this.enable(this.submitButtonTarget)\n }\n\n sendNow() {\n this.showSendNowLabel()\n this.enableSubmitButton()\n this.scheduleDatePickerTarget.classList.add(\"hidden\")\n\n this.disable(this.dateTarget)\n\n this.dispatch('disable', {\n target: this.hourTarget,\n })\n\n this.dispatch('hide', {\n target: this.hourTarget,\n })\n }\n\n schedule() {\n this.showScheduledLabel()\n\n this.submitButtonTarget.disabled = !this.filledInputs\n this.removeClass(this.scheduleDatePickerTarget, \"hidden\")\n\n this.enable(this.dateTarget)\n\n this.dispatch('enable', {\n target: this.hourTarget,\n })\n }\n\n disableSubmitTillInputsAreFilled() {\n this.submitButtonTarget.disabled = !this.filledInputs\n }\n\n setHourForDate({ detail }) {\n this.hourValue = detail\n }\n\n // private\n\n withinNightHours(hour, minute) {\n const time = new Date(0, 0, 0, hour, minute || 0)\n return time >= this.startsAt && time <= this.endsAt\n }\n\n get startsAt() {\n const [startsAtHour, startsAtMinute] = this.nightHoursStartValue.split(\":\").map((value) => parseInt(value))\n return new Date(0, 0, 0, startsAtHour, startsAtMinute)\n }\n\n get endsAt() {\n const [endsAtHour, endsAtMinute] = this.nightHoursEndValue.split(\":\").map((value) => parseInt(value))\n return new Date(0, 0, this.spansTwoDays ? 1 : 0, endsAtHour, endsAtMinute)\n }\n\n get spansTwoDays() {\n const [startsAtHour, _] = this.nightHoursStartValue.split(\":\").map((value) => parseInt(value))\n const [endsAtHour, __] = this.nightHoursEndValue.split(\":\").map((value) => parseInt(value))\n\n return startsAtHour > endsAtHour\n }\n\n get filledInputs() {\n return [this.dateTarget].every(\n (input) => input.value.trim().length > 0\n )\n }\n}\n"],"names":["delivery_controller","ApplicationController","detail","hour","minute","time","startsAtHour","startsAtMinute","value","endsAtHour","endsAtMinute","_","__","input","__publicField"],"mappings":"uNAEe,MAAKA,UAASC,CAAsB,CAWjD,YAAa,CACX,KAAK,iBAAgB,CACzB,CAEE,kBAAmB,CACjB,KAAK,mBAAmB,UAAY,KAAK,iBAC7C,CAEE,oBAAqB,CACnB,KAAK,mBAAmB,UAAY,KAAK,mBAC7C,CAEE,oBAAqB,CACnB,KAAK,OAAO,KAAK,kBAAkB,CACvC,CAEE,SAAU,CACR,KAAK,iBAAgB,EACrB,KAAK,mBAAkB,EACvB,KAAK,yBAAyB,UAAU,IAAI,QAAQ,EAEpD,KAAK,QAAQ,KAAK,UAAU,EAE5B,KAAK,SAAS,UAAW,CACvB,OAAQ,KAAK,UACd,CAAA,EAED,KAAK,SAAS,OAAQ,CACpB,OAAQ,KAAK,UACd,CAAA,CACL,CAEE,UAAW,CACT,KAAK,mBAAkB,EAEvB,KAAK,mBAAmB,SAAW,CAAC,KAAK,aACzC,KAAK,YAAY,KAAK,yBAA0B,QAAQ,EAExD,KAAK,OAAO,KAAK,UAAU,EAE3B,KAAK,SAAS,SAAU,CACtB,OAAQ,KAAK,UACd,CAAA,CACL,CAEE,kCAAmC,CACjC,KAAK,mBAAmB,SAAW,CAAC,KAAK,YAC7C,CAEE,eAAe,CAAE,OAAAC,GAAU,CACzB,KAAK,UAAYA,CACrB,CAIE,iBAAiBC,EAAMC,EAAQ,CAC7B,MAAMC,EAAO,IAAI,KAAK,EAAG,EAAG,EAAGF,EAAMC,GAAU,CAAC,EAChD,OAAOC,GAAQ,KAAK,UAAY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