{"version":3,"file":"map_item_controller-bZCC4ZA2.js","sources":["../../../app/javascript/controllers/import/map_item_controller.js"],"sourcesContent":["import { computePosition, autoUpdate, flip } from '@floating-ui/dom'\n\nimport ApplicationController from '../application_controller'\n\nexport default class extends ApplicationController {\n static targets = [\n 'selectedIcon',\n 'unselectedIcon',\n 'importCheckbox',\n 'dateFormat',\n 'dateFormatMenu',\n 'dateFormatButton',\n 'dateFormatInputsContainer',\n 'option',\n 'select',\n ]\n\n connect() {\n if(this.hasImportCheckboxTarget) {\n this.setupCheckbox()\n this.importCheckboxTarget.addEventListener('change', this.toggle.bind(this))\n }\n }\n\n disconnect() {\n super.disconnect()\n\n if(this.hasImportCheckboxTarget) {\n this.importCheckboxTarget.removeEventListener('change', this.toggle.bind(this))\n }\n }\n\n setupCheckbox() {\n this.updateDisplay()\n }\n\n toggle() {\n this.importCheckboxTarget.checked = !this.importCheckboxTarget.checked\n this.updateDisplay()\n }\n\n updateDisplay() {\n const isChecked = this.importCheckboxTarget.checked\n const isSelected = this.selectTarget.querySelector('x-placeholder').childNodes.length > 1\n || this.selectTarget.querySelector('x-placeholder').childNodes[0].nodeType !== Node.TEXT_NODE\n\n this.selectedIconTarget.classList.toggle('hidden', !isChecked)\n this.unselectedIconTarget.classList.toggle('hidden', isChecked)\n\n this.data.set('checked', isChecked)\n this.data.set('selected', isSelected)\n\n this.triggerEvent()\n }\n\n check() {\n this.importCheckboxTarget.checked = true\n this.updateDisplay()\n }\n\n uncheck() {\n this.importCheckboxTarget.checked = false\n this.updateDisplay()\n }\n\n select({ currentTarget }) {\n if(!['date', 'birthday'].includes(currentTarget.dataset.kind) && this.chosenDateFormatButton) {\n this.removeClass(this.chosenDateFormatButton, 'bg-lavender-light')\n }\n }\n\n showDateFormatMenu({ currentTarget }) {\n if(!['date', 'birthday'].includes(currentTarget.dataset.kind)) {\n return this.hideDateFormatMenu()\n }\n\n this.hoveredElement = currentTarget\n\n this.floatingUICleanup = autoUpdate(currentTarget, this.dateFormatMenuTarget, () => {\n computePosition(currentTarget, this.dateFormatMenuTarget, {\n placement: 'right-end',\n }).then(({x, y}) => {\n Object.assign(this.element.style, {\n top: `${y}px`,\n })\n })\n })\n\n this.show(this.dateFormatMenuTarget)\n }\n\n hideDateFormatMenu() {\n if(!this.hasDateFormatMenuTarget) return\n\n this.hide(this.dateFormatMenuTarget)\n\n if(this.floatingUICleanup) {\n this.floatingUICleanup()\n }\n }\n\n selectFormatForDate({ currentTarget }) {\n this.hoveredElement.querySelector('x-placeholder-content p').innerHTML = currentTarget.dataset.value\n\n this.hoveredElement.click()\n this.hideDateFormatMenu()\n\n this.dateFormatTarget.value = currentTarget.dataset.value\n\n if(this.chosenDateFormatButton) {\n this.removeClass(this.chosenDateFormatButton, 'bg-lavender-light')\n }\n\n this.chosenDateFormatButton = currentTarget\n this.addClass(currentTarget, 'bg-lavender-light')\n }\n\n triggerEvent() {\n const event = new Event('import-map-item:change')\n this.targets.element.dispatchEvent(event);\n }\n}\n"],"names":["map_item_controller","ApplicationController","isChecked","isSelected","currentTarget","autoUpdate","computePosition","x","y","event","__publicField"],"mappings":"2QAIe,MAAKA,UAASC,CAAsB,CAajD,SAAU,CACL,KAAK,0BACN,KAAK,cAAa,EAClB,KAAK,qBAAqB,iBAAiB,SAAU,KAAK,OAAO,KAAK,IAAI,CAAC,EAEjF,CAEE,YAAa,CACX,MAAM,WAAU,EAEb,KAAK,yBACN,KAAK,qBAAqB,oBAAoB,SAAU,KAAK,OAAO,KAAK,IAAI,CAAC,CAEpF,CAEE,eAAgB,CACd,KAAK,cAAa,CACtB,CAEE,QAAS,CACP,KAAK,qBAAqB,QAAU,CAAC,KAAK,qBAAqB,QAC/D,KAAK,cAAa,CACtB,CAEE,eAAgB,CACd,MAAMC,EAAY,KAAK,qBAAqB,QACtCC,EAAa,KAAK,aAAa,cAAc,eAAe,EAAE,WAAW,OAAS,GACnF,KAAK,aAAa,cAAc,eAAe,EAAE,WAAW,CAAC,EAAE,WAAa,KAAK,UAEtF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