{"version":3,"file":"time_controller-B1isW0nk.js","sources":["../../../app/javascript/controllers/artifact/entity/time_controller.js"],"sourcesContent":["import DateController from '@/controllers/property/date_controller'\n\nexport default class extends DateController {\n static values = {\n hour: String,\n minute: String,\n }\n\n static targets = [\n 'hourInput',\n 'minuteInput',\n ]\n\n initialize() {\n if(this.element.dataset.kind === 'time') {\n this.hourValue = this.hourInputTarget.value\n this.minuteValue = this.minuteInputTarget.value\n }\n\n super.initialize()\n }\n\n submit() {\n this.dayValue = this.dayTarget.value\n this.monthValue = this.monthTarget.value\n this.yearValue = this.yearTarget.value\n\n this.show(this.buttonTarget)\n this.hide(this.containerTarget)\n\n if(this.element.dataset.kind === 'time') {\n this.buttonTarget.textContent = t.time.formats.day_month_comma_year_hour_minute\n .replace(\"%d\", this.dayValue)\n .replace(\"%b\", t.date.abbr_month_names[parseInt(this.monthValue)])\n .replace(\"%Y\", this.yearValue)\n .replace(\"%H\", this.hourValue)\n .replace(\"%M\", this.minuteValue)\n } else {\n this.buttonTarget.textContent = t.time.formats.month_day_year\n .replace(\"%B\", t.date.abbr_month_names[parseInt(this.monthValue)])\n .replace(\"%-d\", this.dayValue)\n .replace(\"%Y\", this.yearValue)\n }\n\n this.validate()\n\n this.addClass(this.buttonTarget, 'font-medium')\n this.removeClass(this.buttonTarget, 'text-night-60')\n }\n\n blur() {\n this.buttonTarget.classList.remove(\"hidden\")\n this.containerTarget.classList.add(\"hidden\")\n\n this.validate()\n }\n\n restore() {\n this.blur()\n\n this.dayTarget.value = this.dayValue\n this.monthTarget.value = this.monthValue\n this.yearTarget.value = this.yearValue\n\n this.validate()\n }\n\n onTimeSelect({ detail: time }) {\n const parts = time.split(':')\n\n this.hourValue = parts[0]\n this.minuteValue = parts[1]\n\n this.hourInputTarget.value = parseInt(this.hourValue)\n this.minuteInputTarget.value = parseInt(this.minuteValue)\n\n this.validate()\n this.focus(this.dayTarget, { moveCursorToEnd: true })\n }\n\n onClickOutside({ target }) {\n if(this.isInvisible(this.containerTarget) || this.element.contains(target)) return\n\n if(this.allInputs.every(input => input.value)) {\n this.submit()\n } else {\n this.restore()\n }\n }\n\n validate() {\n if(!this.element.hasAttribute('data-required')) return\n\n if(this.allInputs.every(input => input.value)) {\n this.element.setAttribute('data-valid', true)\n } else {\n this.element.removeAttribute('data-valid')\n }\n\n this.dispatch('validation', {\n prefix: 'property',\n })\n }\n\n get allInputs() {\n return this.element.dataset.kind === 'time' ? this.timeInputs : this.dateInputs\n }\n\n get timeInputs() {\n return [\n this.hourInputTarget,\n this.minuteInputTarget,\n this.dayTarget,\n this.monthTarget,\n this.yearTarget\n ]\n }\n\n get dateInputs() {\n return [\n this.dayTarget,\n this.monthTarget,\n this.yearTarget\n ]\n }\n}\n"],"names":["time_controller","DateController","time","parts","target","input","__publicField"],"mappings":"sNAEe,MAAKA,UAASC,CAAe,CAW1C,YAAa,CACR,KAAK,QAAQ,QAAQ,OAAS,SAC/B,KAAK,UAAY,KAAK,gBAAgB,MACtC,KAAK,YAAc,KAAK,kBAAkB,OAG5C,MAAM,WAAU,CACpB,CAEE,QAAS,CACP,KAAK,SAAW,KAAK,UAAU,MAC/B,KAAK,WAAa,KAAK,YAAY,MACnC,KAAK,UAAY,KAAK,WAAW,MAEjC,KAAK,KAAK,KAAK,YAAY,EAC3B,KAAK,KAAK,KAAK,eAAe,EAE3B,KAAK,QAAQ,QAAQ,OAAS,OAC/B,KAAK,aAAa,YAAc,EAAE,KAAK,QAAQ,iCAC5C,QAAQ,KAAM,KAAK,QAAQ,EAC3B,QAAQ,KAAM,EAAE,KAAK,iBAAiB,SAAS,KAAK,UAAU,CAAC,CAAC,EAChE,QAAQ,KAAM,KAAK,SAAS,EAC5B,QAAQ,KAAM,KAAK,SAAS,EAC5B,QAAQ,KAAM,KAAK,WAAW,EAEjC,KAAK,aAAa,YAAc,EAAE,KAAK,QAAQ,eAC5C,QAAQ,KAAM,EAAE,KAAK,iBAAiB,SAAS,KAAK,UAAU,CAAC,CAAC,EAChE,QAAQ,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