{"version":3,"file":"assignment_action_controller-DU_Ph5Nw.js","sources":["../../../app/javascript/controllers/automation/assignment_action_controller.js"],"sourcesContent":["import ApplicationController from \"@/controllers/application_controller\"\n\nimport { commaSeperatedListWithAndConjunction } from \"@/controllers/models/sentence\";\n\nexport default class extends ApplicationController {\n static values = {\n kind: String,\n }\n\n static targets = [\n 'action',\n 'trigger',\n 'removeButton',\n 'tags',\n 'label',\n 'labelContainer',\n 'user',\n 'kindInput',\n 'targetsInput',\n 'popover',\n ]\n\n connect() {\n if(this.element.dataset.hideKind) {\n this.hide(this.actionTargets.find(action => action.dataset.kind === this.element.dataset.hideKind))\n this.element.removeAttribute('data-hide-kind')\n }\n\n super.connect()\n }\n\n hideUsedKinds({ detail: kindsToHide }) {\n this.actionTargets.forEach((action) => {\n if(kindsToHide.includes(action.dataset.kind)) {\n this.hide(action)\n } else {\n this.show(action)\n }\n })\n }\n\n onActionChange({ currentTarget }) {\n const { kind } = currentTarget.dataset\n this.kindValue = kind\n\n this.labelTarget.innerText = currentTarget.dataset.label\n this.replaceClass(this.labelTarget, 'text-night-60', 'font-medium')\n\n this.dispatch('set', {\n detail: kind,\n })\n\n this.show(this.removeButtonTarget)\n }\n\n toggleTags() {\n if(['label', 'unlabel'].includes(this.kindValue)) {\n this.show(this.tagsTarget)\n this.dispatch('focus', {\n target: this.tagsTarget,\n })\n } else {\n this.hide(this.tagsTarget)\n this.dispatch('clear', {\n target: this.tagsTarget,\n })\n }\n }\n\n assignUser({ currentTarget }) {\n this.kindValue = 'assign'\n\n const avatar = currentTarget.querySelector('[data-icon]').cloneNode(true)\n const { name, id } = currentTarget.dataset\n\n this.labelContainerTarget.prepend(avatar)\n\n this.labelTarget.innerText = t.automation.assignment_actions.assignment_action.assign.replace('%{name}', name)\n this.replaceClass(this.labelTarget, 'text-night-60', 'font-medium')\n\n this.toggleTags()\n\n this.dispatch('set', {\n detail: this.kindValue,\n })\n\n this.show(this.removeButtonTarget)\n\n this.userTargets.forEach(item => {\n if(item === currentTarget) {\n this.addClass(item, 'bg-lavender-light')\n } else {\n this.removeClass(item, 'bg-lavender-light')\n }\n })\n\n this.targetsInputTarget.value = id\n }\n\n setTagTargets({ detail: tagsToAdd }) {\n this.targetsInputTarget.value = tagsToAdd.join(',')\n }\n\n remove() {\n this.element.remove()\n }\n\n toSentence() {\n if(!this.kindValue) return\n\n if(this.kindValue === 'label' || this.kindValue === 'unlabel') {\n const listNames = this.targetsInputTarget.value.split(',')\n\n if(listNames.count === 0) {\n return\n }\n\n const count = listNames.length === 1 ? 'one' : 'other'\n\n return t.automation.assignment_actions.assignment_action[this.kindValue][count].replace(\n '%{tags}',\n commaSeperatedListWithAndConjunction(listNames)\n )\n } else {\n return this.labelTarget.innerText\n }\n }\n\n kindValueChanged() {\n this.actionTargets.forEach((action) => {\n if(action.dataset.kind === this.kindValue) {\n this.addClass(action, 'bg-lavender-light')\n } else {\n this.removeClass(action, 'bg-lavender-light')\n }\n })\n\n this.toggleTags()\n this.element.setAttribute('data-kind', this.kindValue)\n\n this.kindInputTarget.value = this.kindValue\n\n if(this.kindValue) {\n this.nextTick(() => {\n this.triggerTarget.classList.add('!border-night-10', '!cursor-default')\n\n this.dispatch('disable', {\n target: this.popoverTarget,\n })\n })\n }\n }\n}\n"],"names":["assignment_action_controller","ApplicationController","action","kindsToHide","currentTarget","kind","avatar","name","id","item","tagsToAdd","listNames","count","commaSeperatedListWithAndConjunction","__publicField"],"mappings":"kQAIe,MAAKA,UAASC,CAAsB,CAkBjD,SAAU,CACL,KAAK,QAAQ,QAAQ,WACtB,KAAK,KAAK,KAAK,cAAc,KAAKC,GAAUA,EAAO,QAAQ,OAAS,KAAK,QAAQ,QAAQ,QAAQ,CAAC,EAClG,KAAK,QAAQ,gBAAgB,gBAAgB,GAG/C,MAAM,QAAO,CACjB,CAEE,cAAc,CAAE,OAAQC,GAAe,CACrC,KAAK,cAAc,QAASD,GAAW,CAClCC,EAAY,SAASD,EAAO,QAAQ,IAAI,EACzC,KAAK,K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