{"version":3,"file":"inputs_controller-DIXAhJwj.js","sources":["../../../app/javascript/controllers/capture/inputs_controller.js"],"sourcesContent":["import { get } from '@rails/request.js'\n\nimport ApplicationController from '../application_controller'\nimport Sortable from \"sortablejs\";\n\nexport default class extends ApplicationController {\n static values = {\n url: String,\n }\n\n static targets = [\n 'menu',\n 'trigger',\n 'item',\n 'inputList',\n 'inputTemplate',\n ]\n\n connect() {\n super.connect()\n\n this.sortable = Sortable.create(this.inputListTarget, {\n group: 'inputs',\n animation: 150,\n filter: \".not-draggable\",\n onEnd: this.onDragEnd.bind(this),\n preventOnFilter: false\n })\n }\n\n async add({ currentTarget }) {\n const query = {\n kind: currentTarget.dataset.kind,\n position: this.inputListTarget.children.length + 1,\n }\n\n if(currentTarget.hasAttribute('data-property')) {\n query.property_id = currentTarget.getAttribute('data-property')\n }\n\n await get(this.urlValue, {\n query,\n responseKind: 'turbo-stream'\n })\n\n currentTarget.classList.add('hidden')\n\n this.dispatch('selected', {\n detail: query.property_id || query.kind\n })\n }\n\n async replace({ currentTarget }) {\n const { replace, propertyId } = currentTarget.dataset\n\n const query = {\n kind: currentTarget.dataset.kind,\n perform: 'replace'\n }\n\n if(currentTarget.hasAttribute('data-option-value')) {\n query.property_id = currentTarget.getAttribute('data-option-value')\n }\n\n await get(this.urlValue, {\n query,\n responseKind: 'turbo-stream'\n })\n\n this.inputTemplateTargets.find(template => template.dataset.kind === replace).classList.remove('hidden')\n this.inputTemplateTargets.find(template => template.dataset.kind === currentTarget.dataset.kind).classList.add('hidden')\n\n this.dispatch('replaced', {\n detail: {\n replaced: propertyId || replace,\n with: query.property_id || query.kind\n }\n })\n }\n\n hideSelectedInputTypes() {\n this.inputTemplateTargets\n .filter(template => this.selectedInputTypes.includes(template.dataset.kind) || this.selectedInputTypes.includes(template.dataset.propertyId))\n .forEach(template => template.classList.add('hidden'))\n }\n\n focus({ detail }) {\n this.element.classList.add('border-tiger', 'border-solid')\n this.triggerTarget.classList.remove('hidden')\n\n if(detail.menu !== this.menuTarget) {\n this.menuTarget.classList.add(\"hidden\")\n this.menuTarget.removeAttribute(\"aria-expanded\")\n }\n }\n\n blur() {\n if(this.isInvisible(this.menuTarget)) return\n this.triggerTarget.click()\n }\n\n removeFocus({ detail: { menu }}) {\n if(this.isVisible(this.menuTarget) && menu !== this.menuTarget) return\n\n this.element.classList.remove('border-solid', 'border-tiger')\n this.triggerTarget.classList.add('hidden')\n }\n\n onDragEnd(event) {\n // do nothing\n }\n\n itemTargetConnected() {\n if(this.itemTargets.length === 1) {\n this.nextTick(() => {\n this.dispatch('require', {\n target: this.itemTargets[0]\n })\n })\n } else {\n this.itemTargets.forEach(item => {\n this.dispatch('enable', {\n target: this.itemTargets[0]\n })\n })\n }\n\n if(document.querySelector('button[data-form-target=\"submit\"]')) {\n document.querySelector('button[data-form-target=\"submit\"]').disabled = this.missingRequiredInputs\n }\n\n if(this.missingRequiredInputs) {\n if(this.hasShownToast) return\n\n this.hasShownToast = true\n this.showToast({\n message: this.translations.html.inputs.missing_required_fields,\n type: 'error'\n })\n } else {\n this.hasShownToast = false\n }\n }\n\n get missingRequiredInputs() {\n return !(this.itemKinds.includes('email') || this.itemKinds.includes('phone'))\n }\n\n get itemKinds() {\n return this.itemTargets.map(item => item.dataset.inputType)\n }\n\n itemTargetDisconnected() {\n this.itemTargetConnected()\n }\n\n get hiddenInputTypes() {\n return this.inputTemplateTargets\n .filter(template => template.classList.contains('hidden'))\n .map(template => template.dataset.property || template.dataset.kind)\n }\n\n get selectedInputTypes() {\n return window.selectedInputTypes || []\n }\n}\n"],"names":["inputs_controller","ApplicationController","Sortable","currentTarget","query","get","replace","propertyId","template","detail","menu","event","item","__publicField"],"mappings":"8SAKe,MAAKA,UAASC,CAAsB,CAajD,SAAU,CACR,MAAM,QAAO,EAEb,KAAK,SAAWC,EAAS,OAAO,KAAK,gBAAiB,CACpD,MAAO,SACP,UAAW,IACX,OAAQ,iBACR,MAAO,KAAK,UAAU,KAAK,IAAI,EAC/B,gBAA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