{"version":3,"file":"array_controller-DYcaTjfh.js","sources":["../../../app/javascript/controllers/artifact/entity/array_controller.js"],"sourcesContent":["import PropertyController from './property_controller'\n\nimport { commaSeperatedListWithAndConjunction } from '@/controllers/models/sentence';\n\nexport default class extends PropertyController {\n static values = {\n value: Array,\n }\n\n static targets = [\n 'valueInput',\n 'valueInputTemplate',\n ]\n\n initialize() {\n this.valueValue = this.valueInputTargets.map(input => input.value)\n\n super.initialize()\n }\n\n restore() {\n this.hide(this.inputSectionTarget)\n this.show(this.placeholderButtonTarget)\n\n if(this.valueValue.length >= 1) {\n this.placeholderButtonTarget.textContent = commaSeperatedListWithAndConjunction(this.valueValue)\n } else {\n this.placeholderButtonTarget.textContent = t.actions.click_to_add\n }\n }\n\n set({ detail: values }) {\n this.newValues = values\n }\n\n save() {\n this.valueValue = this.newValues || this.valueValue\n this.restore()\n\n this.valueInputTargets.forEach(input => input.remove())\n\n this.valueValue.forEach((value, index) => {\n const input = this.valueInputTemplateTarget.cloneNode(true)\n input.setAttribute('data-artifact--entity--array-target', 'valueInput')\n\n input.value = value\n input.disabled = false\n\n this.element.appendChild(input)\n })\n }\n\n valueValueChanged() {\n if(this.valueValue.length > 0) {\n this.removeClass(this.placeholderButtonTarget, 'text-night-60')\n this.addClass(this.placeholderButtonTarget, 'font-medium')\n } else {\n this.removeClass(this.placeholderButtonTarget, 'font-medium')\n this.addClass(this.placeholderButtonTarget, 'text-night-60')\n }\n\n if(!this.element.hasAttribute('data-required')) return\n\n if(this.valueValue.length > 0) {\n this.element.setAttribute('data-valid', true)\n } else {\n this.element.removeAttribute('data-valid')\n }\n\n this.dispatch('validation', {\n prefix: 'property',\n })\n }\n}\n"],"names":["array_controller","PropertyController","input","commaSeperatedListWithAndConjunction","values","value","index","__publicField"],"mappings":"qQAIe,MAAKA,UAASC,CAAmB,CAU9C,YAAa,CACX,KAAK,WAAa,KAAK,kBAAkB,IAAIC,GAASA,EAAM,KAAK,EAEjE,MAAM,WAAU,CACpB,CAEE,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