{"version":3,"file":"vcards_controller-cSSfJenx.js","sources":["../../../app/javascript/controllers/compose/toolbar/vcards_controller.js"],"sourcesContent":["import {get} from \"@rails/request.js\";\n\nimport ApplicationController from \"../../application_controller\"\n\nexport default class extends ApplicationController {\n static values = {\n selected: Array,\n searchUrl: String,\n }\n\n static targets = [\n \"button\",\n \"menu\",\n \"checkbox\",\n \"searchInput\",\n \"clearButton\",\n \"shareContainer\",\n \"shareButton\",\n \"activeList\",\n \"inactiveList\",\n \"typeInput\"\n ]\n\n search() {\n clearTimeout(this.searchTimeout)\n\n this.searchTimeout = setTimeout(() => {\n get(this.searchUrlValue, {\n query: {\n search: this.searchInputTarget.value,\n \"vcard[entries]\": this.selectedValue\n },\n responseKind: \"turbo-stream\"\n })\n }, 100)\n\n if(this.searchInputTarget.value.trim().length > 0) {\n this.clearButtonTarget.classList.replace(\"opacity-0\", \"opacity-100\")\n this.hide(this.activeListTarget)\n } else {\n this.clearButtonTarget.classList.replace(\"opacity-100\", \"opacity-0\")\n this.show(this.activeListTarget)\n }\n }\n\n focus() {\n super.focus(this.searchInputTarget)\n }\n\n clearSearch() {\n this.searchInputTarget.value = \"\"\n this.search()\n }\n\n onCheckboxChange(event) {\n if(event.target.checked) {\n this.selectedValue = [...this.selectedValue, event.target.value]\n this.moveCheckedToActive(event.target)\n } else {\n event.stopPropagation()\n event.preventDefault()\n\n this.selectedValue = this.selectedValue.filter((value) => value !== event.target.value)\n this.moveCheckedToInactive(event.target)\n }\n }\n\n toggle(event) {\n event.target.checked = !event.target.checked\n }\n\n moveCheckedToActive(target) {\n const parent = target.closest(\"li\")\n const originalIndex = Array.from(this.inactiveListTarget.children).indexOf(parent)\n\n parent.setAttribute(\"data-index\", originalIndex)\n\n this.activeListTarget.appendChild(parent)\n }\n\n moveCheckedToInactive(target) {\n const parent = target.closest(\"li\")\n const originalIndex = parent.dataset.index\n const inactiveItems = this.inactiveListTarget.children\n const referenceNode = (originalIndex >= inactiveItems.length) ? null : inactiveItems[originalIndex];\n\n parent.removeAttribute(\"data-index\")\n\n this.inactiveListTarget.insertBefore(parent, referenceNode)\n }\n\n selectedValueChanged() {\n if(this.selectedValue.length === 0) {\n this.shareContainerTarget.classList.add(\"hidden\")\n return\n }\n\n this.shareContainerTarget.classList.remove(\"hidden\")\n\n if(this.selectedValue.length === 1) {\n this.shareButtonTarget.innerText = window.t.actions.share.one\n } else {\n this.shareButtonTarget.innerText = window.t.actions.share.other.replace(\"%{n}\", this.selectedValue.length)\n }\n }\n\n share() {\n document.getElementById(\"vcards-form\").requestSubmit()\n }\n\n closeByEscape(event) {\n if(this.isInvisible(this.menuTarget)) return\n\n this.buttonTarget.click()\n }\n\n enable() {\n super.enable(this.buttonTarget)\n }\n\n disable() {\n super.disable(this.buttonTarget)\n }\n\n remove() {\n this.typeInputTarget.remove()\n }\n}\n"],"names":["vcards_controller","ApplicationController","get","event","value","target","parent","originalIndex","inactiveItems","referenceNode","__publicField"],"mappings":"+PAIe,MAAKA,UAASC,CAAsB,CAmBjD,QAAS,CACP,aAAa,KAAK,aAAa,EAE/B,KAAK,cAAgB,WAAW,IAAM,CACpCC,EAAI,KAAK,eAAgB,CACvB,MAAO,CACL,OAAQ,KAAK,kBAAkB,MAC/B,iBAAkB,KAAK,aACxB,EACD,aAAc,cACf,CAAA,CACP,EAAO,GAAG,EAEH,KAAK,kBAAkB,MAAM,KAAM,EAAC,OAAS,GAC9C,KAAK,kBAAkB,UAAU,QAAQ,YAAa,aAAa,EACnE,KAAK,KAAK,KAAK,gBAAgB,IAE/B,KAAK,kBAAkB,UAAU,QAAQ,cAAe,WAAW,EACnE,KAAK,KAAK,KAAK,gBAAgB,EAErC,CAEE,OAAQ,CACN,MAAM,MAAM,KAAK,iBAAiB,CACtC,CAEE,aAAc,CACZ,KAAK,kBAAkB,MAAQ,GAC/B,KAAK,OAAM,CACf,CAEE,iBAAiBC,EAAO,CACnBA,EAAM,OAAO,SACd,KAAK,cAAgB,CAAC,GAAG,KAAK,cAAeA,EAAM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