{"version":3,"file":"coupon_controller-BckRN9uO.js","sources":["../../../app/javascript/controllers/compose/toolbar/coupon_controller.js"],"sourcesContent":["import { get } from '@rails/request.js'\n\nimport ApplicationController from '../../application_controller'\n\nexport default class extends ApplicationController {\n static values = { url: String, coupon: Object }\n static targets = [\n \"menu\",\n \"active\",\n \"noneOption\",\n \"tags\",\n \"selected\",\n \"checkbox\",\n \"option\",\n ]\n\n connect() {\n if (Object.keys(this.couponValue).length !== 0) {\n this.dispatch(\"set\", {\n detail: this.couponValue,\n })\n }\n }\n\n async showPane() {\n await get(this.urlValue, { responseKind: \"turbo-stream\" })\n window.dispatchEvent(new CustomEvent(\"coupon:show\"))\n }\n\n setCoupon({ currentTarget }) {\n this.noneOptionTarget.classList.remove(\"hidden\")\n this.tagsTarget.classList.remove(\"hidden\")\n\n this.dispatch(\"set\", {\n detail: JSON.parse(currentTarget.dataset.coupon),\n })\n }\n\n onCouponCreated(e) {\n this.dispatch(\"set\", {\n detail: JSON.parse(e.dataset.coupon)\n })\n }\n\n selectedTargetConnected() {\n this.dispatch(\"set\", {\n detail: JSON.parse(this.selectedTarget.dataset.coupon),\n })\n }\n\n unsetCoupon() {\n window.coupon = undefined\n this.noneOptionTarget.classList.add(\"hidden\")\n this.tagsTarget.classList.add(\"hidden\")\n\n this.dispatch(\"unset\")\n }\n\n insertTag({ currentTarget }) {\n this.dispatch(\"insert-tag\", {\n detail: currentTarget.dataset.tag,\n })\n }\n\n hideByEscape() {\n if(this.isInvisible(this.menuTarget)) return\n\n this.activeTarget.click()\n }\n\n enable() {\n super.enable(this.activeTarget)\n }\n\n disable() {\n super.disable(this.activeTarget)\n }\n\n inheritCouponFromTemplate({ detail: coupon }) {\n if(this.optionTargets.length === 0) return\n\n if(coupon) {\n this.inheritedCouponFromTemplate = coupon\n this.optionTargets.find(option => option.dataset.optionValue === coupon.token).click()\n } else if(this.inheritedCouponFromTemplate) {\n this.noneOptionTarget.click()\n }\n }\n}\n"],"names":["coupon_controller","ApplicationController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