{"version":3,"file":"select_channels_controller-1YPGEwC5.js","sources":["../../../app/javascript/controllers/select_channels_controller.js"],"sourcesContent":["import ApplicationController from './application_controller'\n\nexport default class extends ApplicationController {\n static values = {\n placeholderKind: { type: String, default: 'icon' }\n }\n\n static targets = [\"trigger\", \"menu\", \"defaultIcon\", \"whatsapp\", \"sms\", \"defaultOption\", \"select\", \"tooltip\"]\n\n connect() {\n this.triggerTitle = this.triggerTarget.title\n\n if(this.usesDefaultSettings) {\n this.disableBrowserTitleDialog()\n } else {\n this.disableTooltip()\n }\n }\n\n onDropdownOpen() {\n this.disableTooltip()\n }\n\n onDropdownHide() {\n if(this.usesDefaultSettings && this.tooltipDisabled) {\n this.enableTooltip()\n\n setTimeout(() => {\n const hoveredElement = document.querySelectorAll(':hover').item(\n document.querySelectorAll(':hover').length - 1\n )\n\n // when clicking the trigger button and the cursor is still on the trigger\n // the tooltip will not be shown, this is a way to tell the tooltip to show itself\n if(this.triggerTarget.contains(hoveredElement)) {\n this.dispatch('tooltip:show', {\n target: this.element\n })\n }\n }, 100)\n }\n }\n\n changeTriggerLabel({ currentTarget }) {\n if (currentTarget.dataset.channel === undefined) return\n\n this.triggerTarget.innerHTML = currentTarget.dataset.channel\n this.triggerTarget.classList.replace(\"px-1\", \"px-2\")\n\n this.disableTooltip()\n\n this.dispatch(\"attachment:remove\", {target: document.documentElement })\n\n this.dispatch('change', {\n detail: {\n technology: currentTarget.dataset.technology,\n identifier: currentTarget.dataset.identifier,\n channelId: currentTarget.dataset.optionValue,\n id: currentTarget.dataset.id\n }\n })\n }\n\n useDefault() {\n this.triggerTarget.classList.replace(\"px-2\", \"px-1\")\n\n if(this.placeholderKindValue === 'icon') {\n this.triggerTarget.innerHTML = this.defaultIconTarget.innerHTML\n } else {\n this.triggerTarget.innerHTML = this.translations.informational.using_default_settings\n }\n\n this.enableTooltip()\n\n this.dispatch('change', {\n detail: {\n technology: 'default',\n identifier: 'default',\n }\n })\n\n this.element.setAttribute('data-dropdown-open-value', false)\n }\n\n closeByEscape() {\n if(this.isInvisible(this.menuTarget)) return\n this.triggerTarget.click()\n }\n\n // private\n\n disableTooltip() {\n if(!this.hasTooltipTarget) return\n\n this.element.setAttribute('data-tooltip-disabled', true)\n this.triggerTarget.title = this.triggerTitle\n }\n\n enableTooltip() {\n if(!this.hasTooltipTarget) return\n\n this.element.removeAttribute('data-tooltip-disabled')\n this.disableBrowserTitleDialog()\n }\n\n disableBrowserTitleDialog() {\n this.triggerTarget.title = \"\"\n }\n\n syncOrigin({ detail }) {\n const { technology, identifier } = detail\n if(identifier === this.activeOption.dataset.identifier) return\n\n const option = this[`${identifier}Targets`].length > 0 ? this[`${identifier}Targets`][0] : this.defaultOptionTarget\n\n option.setAttribute('data-notoggle', true)\n option.click()\n option.removeAttribute('data-notoggle')\n }\n\n get usesDefaultSettings() {\n return !this.element.querySelector(\"select\").value\n }\n\n get tooltipDisabled() {\n return this.element.hasAttribute('data-tooltip-disabled')\n }\n\n get activeOption() {\n return this.element.querySelector(\"option:checked\")\n }\n}\n"],"names":["select_channels_controller","ApplicationController","hoveredElement","currentTarget","detail","technology","identifier","option","__publicField"],"mappings":"uNAEe,MAAKA,UAASC,CAAsB,CAOjD,SAAU,CACR,KAAK,aAAe,KAAK,cAAc,MAEpC,KAAK,oBACN,KAAK,0BAAyB,EAE9B,KAAK,eAAc,CAEzB,CAEE,gBAAiB,CACf,KAAK,eAAc,CACvB,CAEE,gBAAiB,CACZ,KAAK,qBAAuB,KAAK,kBAClC,KAAK,cAAa,EAElB,WAAW,IAAM,CACf,MAAMC,EAAiB,SAAS,iBAAiB,QAAQ,EAAE,KACzD,SAAS,iBAAiB,QAAQ,EAAE,OAAS,CACvD,EAIW,KAAK,cAAc,SAASA,CAAc,GAC3C,KAAK,SAAS,eAAgB,CAC5B,OAAQ,KAAK,OACd,CAAA,CAEX,EAAS,GAAG,EAEZ,CAEE,mBAAmB,CAAE,cAAAC,GAAiB,CAChCA,EAAc,QAAQ,UAAY,SAEtC,K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