{"version":3,"file":"trigger_controller-BKnP4bZs.js","sources":["../../../app/javascript/controllers/journeys/trigger_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\nimport { useRemove } from \"../mixins/useRemove\"\nimport { get } from \"@rails/request.js\"\n\nexport default class extends Controller {\n static values = {\n checkConflictUrl: String,\n excluded: Boolean,\n initial: Boolean,\n selected: String,\n includeLabel: { type: String, default: \"And is\" },\n excludeLabel: { type: String, default: \"And is not\" },\n }\n\n static targets = [\n \"conflictWarningContainer\",\n \"select\",\n \"anyChannelButton\",\n \"removeButton\",\n \"footerLabel\",\n \"orLabel\",\n \"container\",\n ]\n\n connect() {\n useRemove(this, {\n stopEventPropagation: true,\n })\n\n this.dispatch(\"connected\", {\n target: document.documentElement,\n detail: {\n id: this.element.id,\n excluded: this.excludedValue,\n included: this.included,\n },\n })\n }\n\n disconnect() {\n this.dispatch(\"removed\", {\n target: document.documentElement,\n })\n }\n\n enableRemove({ detail: newTrigger }) {\n if (\n this.element.id === newTrigger.id ||\n !this.initialStep ||\n this.isTriggersDropdown\n )\n return\n\n this.initialValue = this.element.previousElementSibling !== undefined\n\n if (newTrigger.included) {\n console.log(\"allowsing remove\")\n console.log(this.element)\n this.allowTriggerToBeRemoved()\n this.disableAnyChannelOption()\n }\n\n if (newTrigger.excluded) {\n this.footerLabelTarget.classList.remove(\"hidden\")\n }\n }\n\n disableRemove() {\n if (this.isTriggersDropdown) return\n\n if (this.onlyTrigger) {\n this.disallowTriggerRemoval()\n this.enableAnyChannelOption()\n }\n\n if (!this.initialStep && !this.element.previousElementSibling) {\n this.initialValue = true\n\n if (this.excludedValue) {\n this.footerLabelTarget.classList.remove(\"hidden\")\n }\n }\n }\n\n includeSelf({ detail }) {\n if (detail === this.element.id || this.isTriggersDropdown) return\n\n this.excludedValue = false\n this.initialValue = !this.multipleChannelTriggers\n\n this.getConflictInformationFor(this.selectedValue)\n\n if (!this.initialValue) {\n this.orLabelTarget.classList.remove(\"hidden\")\n } else {\n this.orLabelTarget.classList.add(\"hidden\")\n }\n }\n\n excludeSelf({ detail }) {\n if (detail === this.element.id || this.isTriggersDropdown) return\n\n this.excludedValue = true\n this.removeOrLabel()\n this.removeConflictContainer()\n }\n\n disableHasAnyChannel() {\n if (\n !this.initialStep ||\n !this.element.nextElementSibling ||\n this.isTriggersDropdown\n )\n return\n\n this.initialValue = this.element.previousElementSibling === undefined\n this.excludedValue = false\n\n this.dispatch(\"include\", {\n target: document.documentElement,\n detail: this.element.id,\n })\n\n if (this.element.nextElementSibling) {\n this.allowTriggerToBeRemoved()\n this.disableAnyChannelOption()\n this.footerLabelTarget.classList.add(\"hidden\")\n }\n }\n\n checkForConflict({ currentTarget }) {\n this.selectedValue =\n currentTarget.dataset.checkConflictId || currentTarget.value\n\n if (this.included) {\n this.getConflictInformationFor(\n currentTarget.dataset.checkConflictId || currentTarget.value\n )\n }\n }\n\n removeConflictContainer() {\n this.conflictWarningContainerTarget.innerHTML = \"\"\n this.conflictWarningContainerTarget.className = \"\"\n\n this.conflictWarningContainerTarget.removeAttribute(\"data-conflict\")\n if (this.hasFooterLabelTarget) {\n this.footerLabelTarget.innerText = this.excludeLabelValue\n }\n }\n\n selectAnyOption() {\n this.anyOptionValue.selected = true\n }\n\n setSelectedValue() {\n this.selectedValue = \"any\"\n\n if (!this.initialValue) {\n this.orLabelTarget.classList.remove(\"hidden\")\n } else {\n this.orLabelTarget.classList.add(\"hidden\")\n }\n\n this.removeButtonTarget.classList.add(\"hidden\")\n }\n\n // private\n\n getConflictInformationFor(channelId) {\n let query = {\n channable: channelId,\n append_to: this.element.id,\n }\n\n if (this.excludedValue) {\n query.exclude = \"true\"\n }\n\n get(this.checkConflictUrlValue, {\n responseKind: \"turbo-stream\",\n query,\n })\n }\n\n initialValueChanged() {\n if (!this.initialValue || this.isTriggersDropdown) return\n\n if (!this.selectedValue) {\n this.anyChannelButtonTarget.click()\n this.dispatch(\"exclude\", {\n target: document.documentElement,\n detail: this.element.id,\n })\n\n if (this.multipleChannelTriggers) {\n this.footerLabelTarget.classList.remove(\"hidden\")\n }\n }\n }\n\n allowTriggerToBeRemoved() {\n if (this.isTriggersDropdown || this.excludedValue) return\n\n this.removeButtonTarget.classList.remove(\"hidden\")\n }\n\n disallowTriggerRemoval() {\n this.removeButtonTarget.classList.add(\"hidden\")\n this.footerLabelTarget.classList.add(\"hidden\")\n }\n\n disableAnyChannelOption() {\n this.anyChannelButtonTarget.classList.replace(\n \"hover:bg-night-10\",\n \"text-night-40\"\n )\n this.anyChannelButtonTarget.disabled = true\n }\n\n enableAnyChannelOption() {\n this.anyChannelButtonTarget.classList.remove(\"hidden\")\n this.anyChannelButtonTarget.classList.replace(\n \"text-night-40\",\n \"hover:bg-night-10\"\n )\n this.anyChannelButtonTarget.disabled = false\n }\n\n removeOrLabel() {\n if (this.hasOrLabelTarget) {\n this.orLabelTarget.classList.add(\"hidden\")\n }\n }\n\n get anyOptionValue() {\n return Array.from(this.selectTarget.options).find(\n (option) => option.value === \"any\"\n )\n }\n\n get included() {\n return !this.excludedValue\n }\n\n get onlyTrigger() {\n return (\n !this.element.previousElementSibling && !this.element.nextElementSibling\n )\n }\n\n get initialStep() {\n return this.initialValue\n }\n\n get multipleChannelTriggers() {\n return (\n document.querySelectorAll(\n `[data-controller=\"${this.element.dataset.controller}\"]`\n ).length > 1\n )\n }\n\n get isTriggersDropdown() {\n return this.element.id === \"triggers_dropdown\"\n }\n}\n"],"names":["trigger_controller","Controller","useRemove","newTrigger","detail","currentTarget","channelId","query","get","option","__publicField"],"mappings":"2SAIe,MAAKA,UAASC,CAAW,CAoBtC,SAAU,CACRC,EAAU,KAAM,CACd,qBAAsB,EACvB,CAAA,EAED,KAAK,SAAS,YAAa,CACzB,OAAQ,SAAS,gBACjB,OAAQ,CACN,GAAI,KAAK,QAAQ,GACjB,SAAU,KAAK,cACf,SAAU,KAAK,QAChB,CACF,CAAA,CACL,CAEE,YAAa,CACX,KAAK,SAAS,UAAW,CACvB,OAAQ,SAAS,eAClB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