{"version":3,"file":"group_item_controller-UqAxhcTQ.js","sources":["../../../app/javascript/controllers/filter/group_item_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 searchUrl: String,\n property: String\n }\n\n static targets = [\n 'input',\n 'querySelect',\n 'querySelectOption',\n 'searchResultsList',\n 'searchResultsContainer',\n 'resultTemplate',\n 'valuableIdInput',\n 'valuableValueInput',\n 'removeButton'\n ]\n\n scheduleSearchTimeout({ target }) {\n if(!this.searchUrlValue) return\n\n if(!target.value) {\n this.hide(this.searchResultsListTarget)\n this.hide(this.searchResultsContainerTarget)\n this.searchResultsListTarget.innerHTML = ''\n return\n }\n\n this.debounce(this.search.bind(this))\n }\n\n async search() {\n if(!this.inputTarget.value) return\n\n const value = this.inputTarget.value\n const url = this.searchUrlValue\n\n const response = await get(url, {\n query: {\n property: this.propertyValue,\n [this.propertyValue]: value\n }\n })\n\n if(response.ok) {\n const results = await response.json\n this.searchResultsListTarget.innerHTML = ''\n\n results.forEach((result) => {\n const item = this.resultTemplateTarget.cloneNode(true)\n item.classList.remove('hidden')\n\n item.dataset.value = result.value\n item.querySelector('[data-description]').innerText = result.value\n\n this.searchResultsListTarget.appendChild(item)\n })\n\n if(results.length > 0) {\n this.show(this.searchResultsListTarget)\n this.show(this.searchResultsContainerTarget)\n }\n }\n }\n\n apply({ currentTarget }) {\n const { value } = currentTarget.dataset\n\n this.hide(this.searchResultsListTarget)\n this.hide(this.searchResultsContainerTarget)\n\n this.searchResultsListTarget.innerHTML = ''\n this.inputTarget.value = value\n }\n\n hideDropdown({ target }) {\n if(this.isInvisible(this.searchResultsContainerTarget) || this.searchResultsContainerTarget.contains(target)) return\n\n this.hide(this.searchResultsListTarget)\n this.hide(this.searchResultsContainerTarget)\n\n this.searchResultsListTarget.innerHTML = ''\n }\n\n saveState() {\n const value = this.inputTarget.value\n const query = this.querySelectTarget.value\n\n if(!value && this.element.previousElementSibling) {\n return this.removeButtonTarget.click()\n }\n\n this.state = {\n value,\n query,\n }\n }\n\n restoreState() {\n if(!this.state) return\n\n this.inputTarget.value = this.state.value\n this.querySelectOptionTargets.find((option) => option.dataset.optionValue === this.state.query).click()\n }\n\n onQuerySelect() {\n this.focus(this.inputTarget)\n }\n}\n"],"names":["group_item_controller","ApplicationController","target","value","url","response","get","results","result","item","currentTarget","query","option","__publicField"],"mappings":"+PAIe,MAAKA,UAASC,CAAsB,CAkBjD,sBAAsB,CAAE,OAAAC,GAAU,CAChC,GAAI,KAAK,eAET,IAAG,CAACA,EAAO,MAAO,CAChB,KAAK,KAAK,KAAK,uBAAuB,EACtC,KAAK,KAAK,KAAK,4BAA4B,EAC3C,KAAK,wBAAwB,UAAY,GACzC,MACN,CAEI,KAAK,SAAS,KAAK,OAAO,KAAK,IAAI,CAAC,EACxC,CAEE,MAAM,QAAS,CACb,GAAG,CAAC,KAAK,YAAY,MAAO,OAE5B,MAAMC,EAAQ,KAAK,YAAY,MACzBC,EAAM,KAAK,eAEXC,EAAW,MAAMC,EAAIF,EAAK,CAC9B,MAAO,CACL,SAAU,KAAK,cACf,CAAC,KAAK,aAAa,EAAGD,CAC9B,CACK,CAAA,EAED,GAAGE,EAAS,GAAI,CACd,MAAME,EAAU,MAAMF,EAAS,KAC/B,KAAK,wBAAwB,UAAY,GAEzCE,EAAQ,QAASC,GAAW,CAC1B,MAAMC,EAAO,KAAK,qBAAqB,UAAU,EAAI,EACrDA,EAAK,UAAU,OAAO,QAAQ,EAE9BA,EAAK,QAAQ,MAAQD,EAAO,MAC5BC,EAAK,cAAc,oBAAoB,EAAE,UAAYD,EAAO,MAE5D,KAAK,wBAAwB,YAAYC,CAAI,CAC9C,CAAA,EAEEF,EAAQ,OAAS,IAClB,KAAK,KAAK,KAAK,uBAAuB,EACtC,KAAK,KAAK,KAAK,4BAA4B,EAEnD,CACA,CAEE,MAAM,CAAE,cAAAG,GAAiB,CACvB,KAAM,CAAE,MAAAP,CAAO,EAAGO,E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