{"version":3,"file":"pane_controller-BEyPBz8V.js","sources":["../../../app/javascript/controllers/journeys/pane_controller.js"],"sourcesContent":["import PaneController from \"../pane_controller\"\nimport { get } from \"@rails/request.js\"\n\nexport default class extends PaneController {\n static values = {\n stepId: String,\n anyChannel: { type: Boolean, default: false },\n activeTriggerId: String,\n triggerUrl: String,\n initial: String,\n triggerCheckConflictUrl: String,\n replacementUrl: String,\n journeyId: String\n }\n\n static targets = [\n \"modal\",\n \"anyChannelLabel\",\n \"includeLabel\",\n \"extraChannel\",\n \"anyChannelButton\",\n \"triggersSelect\",\n \"newChannelDropdownButton\",\n \"channelsLabel\",\n \"closeModalButton\",\n \"technologySelect\",\n ]\n\n connect() {\n if (this.anyChannelValue) {\n this.currentTarget = this.element.querySelector(\"[data-expands]\")\n }\n\n this.triggers = Array.from(\n document.querySelectorAll(\"select[name='triggers[]']\")\n ).map((select) => select.value)\n }\n\n show({ detail }) {\n if (detail === this.element.id) {\n super.show()\n this.afterShow()\n }\n\n if (detail !== this.element.id && !this.hidden) {\n this._hide()\n }\n }\n\n toggle({ detail }) {\n if (detail === this.element.id) {\n if (!this.hasUnsavedChanges) {\n this.element.classList.toggle(\"right-0\")\n this.element.classList.toggle(\"-right-full\")\n }\n\n if (this.visible) {\n window.dispatchEvent(new CustomEvent(\"step:disable-dragging\"))\n this.afterShow()\n } else {\n window.dispatchEvent(new CustomEvent(\"step:enable-dragging\"))\n }\n }\n\n if (detail !== this.element.id && !this.hidden) {\n this._hide()\n }\n }\n\n afterShow() {\n\n }\n\n hide(e) {\n if (e?.detail === this.element.id) {\n if (this.hasUnsavedChanges) {\n this.openModalButtonTarget.click()\n\n e.preventDefault()\n e.stopPropagation()\n window.paneId = this.element.id\n } else {\n super.hide()\n this.cancel()\n }\n }\n }\n\n setActiveTriggerId({ currentTarget }) {\n this.currentTrigger = currentTarget.dataset.triggerId\n this.currentTarget = currentTarget\n this.hasUnsavedChanges = true\n\n window.paneId = this.element.id\n\n if (!currentTarget.dataset.channel) {\n this.element.querySelector(\"#applied_filters\")?.classList.add(\"hidden\")\n this.hideChannelDropdownButton()\n }\n\n if (currentTarget.dataset.expands) {\n this.anyChannelValue = true\n this.element.querySelector(\"#applied_filters\")?.classList.remove(\"hidden\")\n this.showChannelDropdownButton()\n }\n\n if(currentTarget.hasAttribute('data-conversation')) {\n this.technologySelectTarget.classList.remove(\"hidden\")\n } else {\n this.technologySelectTarget.classList.add(\"hidden\")\n }\n }\n\n setActiveTriggerToChannel({ currentTarget }) {\n this.currentTarget = currentTarget\n\n setTimeout(() => {\n this.anyChannelValue =\n currentTarget.dataset.anyChannel !== undefined ||\n this.anyChannelOptionSelected\n }, 0)\n }\n\n setHasUnsavedChanges() {\n this.hasUnsavedChanges = true\n window.paneId = this.element.id\n }\n\n async saveAndHide() {\n this.element.setAttribute('data-saved', 'true')\n\n this.activeTriggerIdValue = this.currentTrigger || this.activeTriggerIdValue\n\n let query = {\n trigger_id:\n this.activeTriggerIdValue === \"channels\"\n ? \"\"\n : this.activeTriggerIdValue,\n }\n\n if (\n this.element\n .querySelector(\"#applied_filters\")\n ?.classList.contains(\"hidden\") === false\n ) {\n this.triggers = Array.from(\n document.querySelectorAll(\"select[name='triggers[]']\")\n ).map((select) => select.value)\n\n query.triggers = this.triggers\n }\n\n this.anyChannelValue = this.currentTarget?.dataset.expands !== undefined\n\n await get(this.triggerUrlValue, {\n responseKind: \"turbo-stream\",\n query,\n })\n\n this.dispatch(\"trigger:set\", {\n target: document.getElementById(\"journeys--editor\"),\n detail: {\n triggerId: this.activeTriggerIdValue,\n isChannelTrigger: false,\n anyChannel: false,\n journey_id: this.journeyIdValue\n },\n })\n\n this.clearQueue()\n this._hide()\n this.hasUnsavedChanges = false\n this.targetTechnologiesValue = this.selectedTechnologyIds\n }\n\n async cancel() {\n if (this.invisible) return\n\n this.hasUnsavedChanges = false\n window.paneId = undefined\n this._hide()\n\n get(this.replacementUrlValue, {\n responseKind: \"turbo-stream\",\n query: {\n trigger_id: this.activeTriggerIdValue,\n triggers: this.triggers,\n journey_id: this.journeyIdValue\n },\n })\n }\n\n setChannels() {}\n\n _abort() {}\n\n _hide() {\n window.dispatchEvent(new CustomEvent(\"step:enable-dragging\"))\n super.hide()\n }\n\n getStream({ currentTarget }) {\n get(currentTarget.dataset.url, { responseKind: \"turbo-stream\" })\n }\n\n showChannelDropdownButton() {\n this.channelsLabelTarget.classList.remove(\"hidden\")\n this.newChannelDropdownButtonTarget.classList.remove(\"hidden\")\n }\n\n hideChannelDropdownButton() {\n this.channelsLabelTarget.classList.add(\"hidden\")\n this.newChannelDropdownButtonTarget.classList.add(\"hidden\")\n }\n\n async getNewChannelDropdown({ currentTarget }) {\n let query = {}\n\n if (this.anyChannelValue) {\n query.exclude = \"yes\"\n }\n\n await get(currentTarget.dataset.url, {\n responseKind: \"turbo-stream\",\n query,\n })\n\n if (this.anyChannelValue) {\n this.anyChannelLabelTargets.forEach((el) => el.classList.remove(\"hidden\"))\n }\n }\n\n setHasAnyChannel() {\n if (this.hasIncludeLabelTarget) {\n this.includeLabelTarget.classList.add(\"hidden\")\n this.anyChannelLabelTarget.classList.remove(\"hidden\")\n }\n }\n\n disableHasAnyChannel() {\n setTimeout(() => {\n if (this.anyChannelOptionSelected) return\n\n this.anyChannelValue = false\n\n if (this.hasIncludeLabelTarget) {\n this.includeLabelTarget.classList.remove(\"hidden\")\n this.anyChannelLabelTarget.classList.add(\"hidden\")\n }\n }, 0)\n }\n\n remove() {\n this.dispatch(\"remove\", {\n detail: this.stepIdValue,\n target: document.documentElement,\n })\n\n this._hide()\n this.element.remove()\n }\n\n hidePane(e) {\n if (\n this.element.contains(e.target) ||\n Array.from(document.querySelectorAll(\"#toast\")).some((toast) =>\n toast.contains(e.target)\n ) ||\n this.invisible ||\n e.target.id.split(\"_trigger\")[0] === this.stepIdValue\n )\n return\n\n if (this.hasUnsavedChanges) {\n this.openModalButtonTarget.click()\n e.preventDefault()\n window.paneId = this.element.id\n } else {\n this._hide()\n this.cancel()\n this.clearQueue()\n }\n }\n\n alertUserAboutUnsavedChanges({ detail: requestingStepId }) {\n if (window.paneId === this.element.id) {\n this.openModalButtonTarget.click()\n }\n }\n\n clearQueue() {\n window.paneId = undefined\n }\n\n get visible() {\n return this.element.classList.contains(\"right-0\")\n }\n\n get anyChannelOptionSelected() {\n return Array.from(\n document.querySelectorAll(\n '[data-controller=\"custom-dropdown journeys--trigger hidden-select\"]'\n )\n )\n .map((element) => element.dataset.selected)\n .find((value) => value === \"any\")\n }\n\n get openModalButtonTarget() {\n return this.element.querySelector(\"[data-open-modal]\")\n }\n}\n"],"names":["PaneController","select","detail","currentTarget","_a","_b","query","get","el","toast","requestingStepId","element","value","__publicField"],"mappings":"8PAGe,MAAKA,UAASA,CAAe,CAyB1C,SAAU,CACJ,KAAK,kBACP,KAAK,cAAgB,KAAK,QAAQ,cAAc,gBAAgB,GAGlE,KAAK,SAAW,MAAM,KACpB,SAAS,iBAAiB,2BAA2B,CACtD,EAAC,IAAKC,GAAWA,EAAO,KAAK,CAClC,CAEE,KAAK,CAAE,OAAAC,GAAU,CACXA,IAAW,KAAK,QAAQ,KAC1B,MAAM,KAAI,EACV,KAAK,UAAS,GAGZA,IAAW,KAAK,QAAQ,IAAM,CAAC,KAAK,QACtC,KAAK,MAAK,CAEhB,CAEE,OAAO,CAAE,OAAAA,GAAU,CACbA,IAAW,KAAK,QAAQ,KACrB,KAAK,oBACR,KAAK,QAAQ,UAAU,OAAO,SAAS,EACvC,KAAK,QAAQ,UAAU,OAAO,aAAa,GAGzC,KAAK,SACP,OAAO,cAAc,IAAI,YAAY,uBAAuB,CAAC,EAC7D,KAAK,UAAS,GAEd,OAAO,cAAc,IAAI,YAAY,sBAAsB,CAAC,GAI5DA,IAAW,KAAK,QAAQ,IAAM,CAAC,KAAK,QACtC,KAAK,MAAK,CAEhB,CAEE,WAAY,CAEd,CAEE,KAAK,EAAG,EACF,iBAAG,UAAW,KAAK,QAAQ,KACzB,KAAK,mBACP,KAAK,sBAAsB,M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