{"version":3,"file":"merge_dropdown_controller-D6Ff-Ozd.js","sources":["../../../app/javascript/controllers/audience/merge_dropdown_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 url: String,\n }\n\n static targets = [\n 'searchInput',\n 'category',\n 'duplicate',\n 'trigger',\n ]\n\n show() {\n if(this.hasSearchInputTarget) {\n this.nextTick(() => {\n this.focus(this.searchInputTarget, { moveCursorToEnd: true })\n })\n }\n }\n\n hide() {\n if(this.hasSearchInputTarget) {\n this.searchInputTarget.value = ''\n }\n }\n\n clear() {\n if(this.hasSearchInputTarget) {\n this.searchInputTarget.value = ''\n }\n\n clearTimeout(this.searchTimeout)\n }\n\n debounceSearch() {\n clearTimeout(this.searchTimeout)\n\n this.searchTimeout = setTimeout(() => {\n this.search()\n })\n }\n\n focus() {\n this.searchInputTarget.focus()\n }\n\n search() {\n get(this.urlValue, {\n responseKind: 'turbo-stream',\n query: {\n search: this.searchInputTarget.value\n }\n })\n }\n\n select() {\n this.duplicateTargets[0]?.click()\n }\n\n review({ currentTarget }) {\n currentTarget.querySelector('[data-review]').click()\n }\n\n duplicateTargetDisconnected() {\n if(!this.hasTriggerTarget) return\n\n if(this.duplicateTargets.length === 0) {\n this.clear()\n this.triggerTarget.classList.add('hidden')\n return this.dispatch('popover:hide', {\n target: this.element\n })\n } else if(this.duplicateTargets.length === 1) {\n this.triggerTarget.querySelector('[data-text]').textContent = t.contacts.merge.label.one\n } else {\n this.triggerTarget.querySelector('[data-text]').textContent = t.contacts.merge.label.other.replace('%{count}', this.duplicateTargets.length)\n }\n\n this.categoryTargets\n .filter(category => category.querySelectorAll('[data-audience--merge-dropdown-target=\"duplicate\"]').length === 0)\n .forEach(category => category.classList.add('hidden'))\n }\n}\n"],"names":["merge_dropdown_controller","ApplicationController","get","_a","currentTarget","category","__publicField"],"mappings":"+PAIe,MAAKA,UAASC,CAAsB,CAYjD,MAAO,CACF,KAAK,sB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