{"version":3,"file":"technologies_controller-A1OuK8Uk.js","sources":["../../../app/javascript/controllers/compose/technologies_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\n\nimport { commaSeperatedListWithAndConjunction } from '@/controllers/models/sentence';\n\nexport default class extends ApplicationController {\n static values = {\n recordType: String,\n }\n\n static targets = [\"all\", \"technology\", \"error\", \"description\"]\n static classes = [\"enabled\", \"disabled\"]\n\n initialize() {\n this.checkAndDisableTechnology = this.checkAndDisableTechnology.bind(this)\n this.checkAndEnableTechnology = this.checkAndEnableTechnology.bind(this)\n\n this.enableTechnology = this.enableTechnology.bind(this)\n }\n\n connect() {\n if (this.allTarget.checked) {\n this.messageLengthChangedToLowest()\n\n this.dispatch('changed', {\n detail: {\n ids: ['all'],\n names: ['all']\n }\n })\n } else {\n this.dispatch('changed', {\n detail: {\n ids: this.checkedTechnologies.map(technology => technology.dataset.hashedId),\n names: this.checkedTechnologies.map(technology => technology.dataset.name),\n }\n })\n }\n\n if (this.checkedTechnologies.length === 1) {\n this.changeMessageLengthToCheckedTechnology(this.checkedTechnologies[0])\n this.checkAndDisableTechnology(this.checkedTechnologies[0])\n }\n }\n\n onSendViaAllClick() {\n if (this.allTarget.checked) {\n this.technologyTargets.forEach(this.checkAndDisableTechnology)\n this.messageLengthChangedToLowest()\n\n this.dispatch('changed', {\n detail: {\n ids: ['all'],\n names: ['all']\n }\n })\n\n if (this.hasErrorTarget) {\n this.hide(this.errorTarget)\n }\n\n if(this.hasDescriptionTarget) {\n this.descriptionTarget.textContent = this.summaryForAllTechnologies\n }\n } else {\n this.technologyTargets.forEach(this.checkAndEnableTechnology)\n this.onTechnologyClick()\n }\n }\n\n onTechnologyClick() {\n if (this.checkedTechnologies.length === 1) {\n this.changeMessageLengthToCheckedTechnology(this.checkedTechnologies[0])\n this.checkAndDisableTechnology(this.checkedTechnologies[0])\n } else {\n this.disabledTechnologies.forEach(this.checkAndEnableTechnology)\n this.messageLengthChangedToLowest()\n }\n\n if(this.hasDescriptionTarget) {\n this.descriptionTarget.textContent = this.summaryForSpecificTechnologies.replace(\n '%{technologies}',\n commaSeperatedListWithAndConjunction(this.checkedTechnologies.map(technology => technology.dataset.formattedName))\n )\n }\n\n if (this.hasErrorTarget) {\n if (this.checkedTechnologies.length === 0) {\n this.show(this.errorTarget)\n } else {\n this.hide(this.errorTarget)\n }\n }\n\n this.dispatch('changed', {\n detail: {\n ids: this.checkedTechnologies.map(technology => technology.dataset.hashedId),\n names: this.checkedTechnologies.map(technology => technology.dataset.name),\n }\n })\n }\n\n restoreSnapshot({technologies}) {\n if (technologies.includes('all')) {\n this.allTarget.checked = true\n this.technologyTargets.forEach(this.checkAndDisableTechnology)\n } else {\n this.allTarget.checked = false\n\n this.technologyTargets.forEach(technology => {\n technology.checked = technologies.includes(technology.dataset.hashedId)\n technology.disabled = false\n\n this.enableTechnology(technology)\n })\n }\n }\n\n // private\n\n changeMessageLengthToCheckedTechnology(technology) {\n this.dispatch(\"messageLengthChange\", {\n detail: {\n name: technology.dataset.name,\n maxMessageLength: Number.parseInt(technology.dataset.maxMessageLength)\n }\n })\n }\n\n messageLengthChangedToLowest() {\n if (!this.technologyWithLowestMessageLength) return\n\n this.dispatch(\"messageLengthChange\", {\n detail: this.technologyWithLowestMessageLength\n })\n }\n\n checkAndDisableTechnology(technologyCheckbox) {\n technologyCheckbox.checked = true\n technologyCheckbox.classList.add('text-gray-300')\n technologyCheckbox.parentElement.classList.add('pointer-events-none')\n\n technologyCheckbox.parentElement.classList.add(...this.disabledClasses)\n technologyCheckbox.parentElement.classList.remove(...this.enabledClasses)\n }\n\n checkAndEnableTechnology(technologyCheckbox) {\n technologyCheckbox.disabled = false\n\n technologyCheckbox.classList.remove('text-gray-300')\n technologyCheckbox.parentElement.classList.remove('pointer-events-none')\n\n this.enableTechnology(technologyCheckbox)\n }\n\n enableTechnology(technologyCheckbox) {\n technologyCheckbox.parentElement.classList.remove(...this.disabledClasses)\n technologyCheckbox.parentElement.classList.add(...this.enabledClasses)\n }\n\n get technologyWithLowestMessageLength() {\n const lowestMessageLength = Math.min(\n ...this.checkedTechnologies.map(checkbox => Number.parseInt(checkbox.dataset.maxMessageLength))\n )\n\n const technology = this.checkedTechnologies.find(\n technology => technology.dataset.maxMessageLength === lowestMessageLength.toString()\n )\n\n\n return technology ? {name: technology.dataset.name, maxMessageLength: lowestMessageLength} : null\n }\n\n get checkedTechnologies() {\n return this.technologyTargets.filter(technology => technology.checked)\n }\n\n get disabledTechnologies() {\n return this.technologyTargets.filter(technology => technology.disabled || technology.classList.contains('text-gray-300'))\n }\n\n get snapshot() {\n return {\n technologies: this.allTarget.checked ? ['all'] : this.checkedTechnologies.map(technology => technology.dataset.hashedId),\n maxMessageLength: this.technologyWithLowestMessageLength?.maxMessageLength\n }\n }\n\n get summaryForAllTechnologies() {\n return this.recordTypeValue === 'Journey' ? t.compose.technologies.journeys.summary.all : t.compose.technologies.summary.all\n }\n\n get summaryForSpecificTechnologies() {\n return this.recordTypeValue === 'Journey' ? t.compose.technologies.journeys.summary.specific : t.compose.technologies.summary.specific\n }\n}\n"],"names":["technologies_controller","ApplicationController","technology","commaSeperatedListWithAndConjunction","technologies","technologyCheckbox","lowestMessageLength","checkbox","_a","__publicField"],"mappings":"kQAIe,MAAKA,UAASC,CAAsB,CAQjD,YAAa,CACX,KAAK,0BAA4B,KAAK,0BAA0B,KAAK,IAAI,EACzE,KAAK,yBAA2B,KAAK,yBAAyB,KAAK,IAAI,EAEvE,KAAK,iBAAmB,KAAK,iBAAiB,KAAK,IAAI,CAC3D,CAEE,SAAU,CACJ,KAAK,UAAU,SACjB,KAAK,6BAA4B,EAEjC,KAAK,SAAS,UAAW,CACvB,OAAQ,CACN,IAAK,CAAC,KAAK,EACX,MAAO,CAAC,KAAK,CACvB,CACO,CAAA,GAED,KAAK,SAAS,UAAW,CACvB,OAAQ,CACN,IAAK,KAAK,oBAAoB,IAAIC,GAAcA,EAAW,QAAQ,QAAQ,EAC3E,MAAO,KAAK,oBAAoB,IAAIA,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