{"version":3,"file":"pane_controller-Doc838UY.js","sources":["../../../app/javascript/controllers/step/message/pane_controller.js"],"sourcesContent":["import PaneController from \"../../journeys/pane_controller\"\nimport {snap} from \"gsap/gsap-core\";\n\nexport default class extends PaneController {\n static values = {\n targetTechnologies: Array,\n body: String,\n stepName: String,\n delivery: String,\n }\n\n static targets = ['compose', 'submit', 'stepNameInput']\n\n initialize() {\n super.initialize()\n\n this.state = {\n body: this.bodyValue,\n maxMessageLength: this.maxMessageLength,\n technologies: [],\n attachments: [],\n }\n\n this.changedState = { ...this.state }\n\n this.delivery = this.deliveryValue\n }\n\n connect() {\n super.connect()\n this.elementSnapshot = this.element.cloneNode(true)\n }\n\n onComposeInitialization({ detail: snapshot }) {\n this.state.body = snapshot.string\n this.state.technologies = snapshot.technologies\n this.state.maxMessageLength = snapshot.maxMessageLength\n this.state.footer = snapshot.footer\n\n this.state.latitude = snapshot.location?.lat\n this.state.longitude = snapshot.location?.lng\n\n this.state.attachments = snapshot.attachments\n this.state.buttons = snapshot.buttons\n\n this.snapshot = this.changedSnapshot = snapshot\n\n this.changedState = {\n ...this.changedState,\n ...this.state\n }\n }\n\n onContentValueChange({ detail }) {\n const { string } = detail\n\n this.changedState.body = string\n this.changedState.footer = detail.footer\n\n this.changedState.latitude = detail.location?.lat\n this.changedState.longitude = detail.location?.lng\n this.changedState.buttons = detail.buttons\n\n this.changedState.attachments = detail.attachments\n this.changedSnapshot = detail\n\n this.submitTarget.disabled = string.length === 0\n }\n\n onMessageLengthChange({ detail }) {\n const { maxMessageLength } = detail\n this.changedState.maxMessageLength = maxMessageLength\n\n if(!this.state.maxMessageLength) {\n this.state.maxMessageLength = maxMessageLength\n }\n\n this.dispatch('technologies:messageLengthChange', {\n target: this.composeTarget,\n detail\n })\n }\n\n onTargetTechnologiesChange({ detail }) {\n this.technologyNames = detail.names\n this.changedState.technologies = detail.ids\n this.submitTarget.disabled = detail.length === 0\n\n this.dispatch('technologies:changed', {\n target: this.composeTarget,\n detail\n })\n }\n\n onDeliveryChange({ detail: delivery }) {\n this.delivery = delivery\n }\n\n save() {\n const { template, templateChanged } = this.changedSnapshot\n\n if(template && ['medium', 'low'].includes(template.quality) && !templateChanged) {\n this.dispatch('show', {\n target: this.element,\n detail: template.quality,\n })\n } else {\n this.saveAndHide()\n }\n }\n\n saveAndHide() {\n if(this.technologyNames.length === 1 && this.technologyNames[0] === 'sms') {\n delete this.changedSnapshot.buttons\n delete this.changedState.buttons\n\n this.changedSnapshot.attachments = this.changedState.attachments = []\n this.changedSnapshot.location = this.changedState.location = null\n\n this.changedSnapshot.footer = this.changedState.footer = ''\n\n this.dispatch('clear', {target: this.composeTarget})\n }\n\n this.state = { ...this.changedState }\n this.stepNameValue = this.stepNameInputTarget.value\n\n this.deliveryValue = this.delivery\n\n this.sync(true)\n this._hide()\n\n this.clearQueue(false)\n\n this.state = { ...this.changedState }\n\n this.snapshot = {\n ...this.changedSnapshot,\n technologies: this.changedState.technologies\n }\n\n this.elementSnapshot = this.element.cloneNode(true)\n }\n\n get hasUnsavedChanges() {\n return this.nameChanged\n || this.changedState.body !== this.state.body\n || this.changedState.maxMessageLength !== this.state.maxMessageLength\n || this.changedState.footer !== this.state.footer\n || this.targetTechnologiesChanged\n || this.changedState.latitude !== this.state.latitude\n || this.changedState.longitude !== this.state.longitude\n || this.buttonsChanged\n || this.changedState.attachments.length !== this.state.attachments.length || this.changedState.attachments.some((attachment, index) => this.state.attachments[index] !== attachment)\n || this.delivery !== this.deliveryValue\n }\n\n get nameChanged() {\n return this.stepNameValue !== this.stepNameInputTarget.value.trim()\n }\n\n sync(commit = false) {\n this.dispatch(\"sync\", {\n detail: {\n stepId: this.stepIdValue,\n body: this.state.body,\n smsCount: 1,\n smsLength: this.maxMessageLength,\n coupon: this.coupon,\n commit,\n pieces: this.changedSnapshot.pieces,\n ...this.changedSnapshot,\n stepName: this.stepNameValue,\n },\n target: document.documentElement,\n })\n }\n\n syncValues() {\n if (this.hasUnsavedChanges) {\n window.paneId = this.element.id\n }\n }\n\n cancel() {\n this._abort()\n this._hide()\n\n setTimeout(this.clearQueue, 1000)\n }\n\n afterShow() {\n this.dispatch('focus', {\n target: this.composeTarget\n })\n }\n\n _abort() {\n this.dispatch(\"sync:abort\", {\n detail: this.stepIdValue,\n target: document.documentElement,\n })\n\n this.element.querySelector('[data-close-modal]').click()\n\n this.delayed(() => {\n this.element.replaceWith(this.elementSnapshot)\n }, 300)\n }\n\n onEnterKeydown({ detail: snapshot }) {\n if(snapshot.string) {\n this.saveAndHide()\n }\n }\n\n editTemplate() {\n this.nextTick(() => {\n this.dispatch('focus', {\n target: this.composeTarget\n })\n },)\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 this.composeTarget.contains(document.activeElement)\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 get targetTechnologiesChanged() {\n return this.state.technologies !== this.changedState.technologies\n }\n\n get buttonsChanged() {\n const changedButtons = this.changedSnapshot.buttons.map(({buttons, type}) => buttons).flat()\n const currentButtons = this.snapshot.buttons.map(({buttons, type}) => buttons).flat()\n\n return changedButtons.length !== currentButtons.length\n || changedButtons.some((button, index) => currentButtons[index].title !== button.title || currentButtons[index].value !== button.value)\n }\n}\n"],"names":["pane_controller","PaneController","snapshot","_a","_b","detail","string","maxMessageLength","delivery","template","templateChanged","attachment","index","commit","e","toast","changedButtons","buttons","type","currentButtons","button","__publicField"],"mappings":"sNAGe,MAAKA,UAASC,CAAe,CAU1C,YAAa,CACX,MAAM,WAAU,EAEhB,KAAK,MAAQ,CACX,KAAM,KAAK,UACX,iBAAkB,KAAK,iBACvB,aAAc,CAAE,EAChB,YAAa,CAAE,CACrB,EAEI,KAAK,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