{"version":3,"file":"toolbar_controller-C2HpTYr0.js","sources":["../../../app/javascript/controllers/compose/toolbar_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\n\nexport default class extends ApplicationController {\n static targets = [\n 'messageLengthCounterContainer',\n 'messageLengthCounter',\n 'tool',\n 'attachment',\n 'recording',\n 'recordButton',\n 'sendButton'\n ]\n\n static values = {\n messageLength: { type: Number, default: 160 },\n enabledTools: Array,\n technology: Object\n }\n\n initialize() {\n super.initialize()\n this.length = 0\n\n this.enableTool = this.enableTool.bind(this)\n this.disableTool = this.disableTool.bind(this)\n\n this.toolIsEnabled = this.toolIsEnabled.bind(this)\n this.toolIsDisabled = this.toolIsDisabled.bind(this)\n\n this.tools = ['attachment', 'location', 'link', 'tag', 'vcard', 'voice', 'emoji']\n this.disabledTools = this.tools.filter(tool => !this.enabledToolsValue.includes(tool))\n }\n\n updateMessageLengthCounter({ detail }) {\n this.length = detail.string.trim().length\n this.messageLengthValueChanged()\n }\n\n updateMaxMessageLength({ detail }) {\n const { name, maxMessageLength } = detail\n\n if(name !== 'sms') {\n return this.hide(this.messageLengthCounterContainerTarget)\n }\n\n if(this.element.dataset.mode === 'message') {\n this.show(this.messageLengthCounterContainerTarget)\n }\n\n this.messageLengthValue = maxMessageLength\n }\n\n onAudioRecordingStarted() {\n this.hide(this.messageLengthCounterContainerTarget)\n this.recordingTargetConnected()\n }\n\n onAudioRecordingCompleted() {\n this.show(this.messageLengthCounterContainerTarget)\n }\n\n enableTools({ detail: tools }) {\n tools.filter(this.toolIsDisabled).forEach(this.enableTool)\n this.disabledTools = this.disabledTools.filter(tool => !tools.includes(tool))\n }\n\n disableTools({ detail: tools }) {\n if(tools === 'all') {\n this.disabledTools = this.toolTargets.map(tool => tool.dataset.kind)\n return this.disabledTools.forEach(this.disableTool)\n }\n\n tools.forEach(this.disableTool)\n this.disabledTools = Array.from(new Set([...this.disabledTools, ...tools]))\n }\n\n enableTool(identifier) {\n this.dispatch('enable', {\n target: this.toolTargets.find(tool => tool.dataset.kind === identifier),\n })\n }\n\n disableTool(identifier) {\n this.dispatch('disable', {\n target: this.toolTargets.find(tool => tool.dataset.kind === identifier),\n })\n }\n\n toolIsEnabled(identifier) {\n return !this.toolIsDisabled(identifier)\n }\n\n toolIsDisabled(identifier) {\n return this.disabledTools.includes(identifier)\n }\n\n attachmentTargetConnected() {\n this.disableTools({ detail: ['vcard', 'voice', 'location'] })\n }\n\n attachmentTargetDisconnected() {\n if(this.attachmentTargets.length > 0) return\n\n ['vcard', 'voice', 'location']\n .filter((identifier) => this.enabledToolsValue.includes(identifier))\n .forEach(this.enableTool)\n }\n\n recordingTargetConnected() {\n this.disableTools({ detail: ['attachment', 'location', 'vcard'] })\n }\n\n recordingTargetDisconnected() {\n ['attachment', 'location', 'vcard']\n .filter((identifier) => this.enabledToolsValue.includes(identifier))\n .forEach(this.enableTool)\n\n if(this.element.dataset.mode === 'message') {\n this.show(this.messageLengthCounterContainerTarget)\n }\n }\n\n onMapVisible() {\n this.disableTools({ detail: ['vcard', 'voice', 'attachment'] })\n }\n\n onMapHidden() {\n ['vcard', 'voice', 'attachment']\n .filter((identifier) => this.enabledToolsValue.includes(identifier))\n .forEach(this.enableTool)\n }\n\n reset() {\n this.toolTargets.forEach(tool => {\n this.dispatch('reset', { target: tool })\n })\n }\n\n syncToolsFromTechnology({ detail }) {\n const { technology, window } = detail\n const { tools, name: identifier } = technology\n\n this.technologyValue = technology\n\n if(identifier === 'sms' && this.element.dataset.mode === 'message') {\n this.show(this.messageLengthCounterContainerTarget)\n } else {\n this.hide(this.messageLengthCounterContainerTarget)\n }\n\n if((!window || !window.open) && identifier !== 'sms') {\n return this.disableTools({ detail: 'all' })\n }\n\n this.enableTools({ detail: tools })\n const toolsToDisable = this.tools.filter(tool => !tools.includes(tool))\n\n this.disableTools({ detail: toolsToDisable })\n }\n\n inheritCouponFromTemplate({ detail: coupon }) {\n this.dispatch('inherit', {\n target: this.toolTargets.find(tool => tool.dataset.kind === 'coupon'),\n detail: coupon,\n })\n }\n\n showSendButton() {\n super.enable(this.sendButtonTarget)\n this.show(this.sendButtonTarget)\n\n this.hide(this.recordButtonTarget)\n }\n\n // private\n\n technologyValueChanged() {\n if(!this.technologyValue) return\n\n this.messageLengthValue = this.technologyValue.max_message_length\n\n this.dispatch('technology:changed', {\n target: this.toolTargets.find(tool => tool.dataset.kind === 'attachment'),\n detail: {\n accept: this.technologyValue.media,\n media: this.technologyValue.media_restrictions,\n }\n })\n }\n\n messageLengthValueChanged() {\n const scope = this.technologyValue.name === 'sms' ? 'sms' : 'other'\n\n this.messageLengthCounterTarget.innerText = this.translations.compose.counter[scope]\n .replace('%{characters_left}', this.remainingCharactersLength)\n .replace('%{messages_count}', this.messagesCount)\n\n if(this.technologyValue.name === 'sms') return\n\n if(this.remainingCharactersLength < 100) {\n this.show(this.messageLengthCounterContainerTarget)\n } else {\n this.hide(this.messageLengthCounterContainerTarget)\n }\n }\n\n get remainingCharactersLength() {\n return this.messageLengthValue - (this.length % this.messageLengthValue)\n }\n\n get messagesCount() {\n return Math.ceil(this.length / this.messageLengthValue) > 0 ? Math.ceil(this.length / this.messageLengthValue) : 1\n }\n}\n"],"names":["toolbar_controller","ApplicationController","tool","detail","name","maxMessageLength","tools","identifier","technology","window","toolsToDisable","coupon","scope","__publicField"],"mappings":"uNAEe,MAAKA,UAASC,CAAsB,CAiBjD,YAAa,CACX,MAAM,WAAU,EAChB,KAAK,OAAS,EAEd,KAAK,WAAa,KAAK,WAAW,KAAK,IAAI,EAC3C,KAAK,YAAc,KAAK,YAAY,KAAK,IAAI,EAE7C,KAAK,cAAgB,KAAK,cAAc,KAAK,IAAI,EACjD,KAAK,eAAiB,KAAK,eAAe,KAAK,IAAI,EAEnD,KAAK,MAAQ,CAAC,aAAc,WAAY,OAAQ,MAAO,QAAS,QAAS,OAAO,EAChF,KAAK,cAAgB,KAAK,MAAM,OAAOC,GAAQ,CAAC,KAAK,kBAAkB,SAASA,CAAI,CAAC,CACzF,CAEE,2BAA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