{"version":3,"file":"radio_controller-BEeowZsH.js","sources":["../../../app/javascript/controllers/audience/radio_controller.js"],"sourcesContent":["import { post } from '@rails/request.js'\n\nimport ApplicationController from '../application_controller'\n\nimport { useNumberHelpers } from '../mixins/useNumberHelpers'\n\nexport default class extends ApplicationController {\n static values = {\n id: String,\n contactId: String,\n checked: Array,\n count: Number,\n exportUrl: String,\n batchUrl: String,\n }\n\n static targets = [\n 'checkbox',\n 'checkAll',\n 'checkAllContainer',\n 'exportButton',\n 'selectionContainer',\n 'selectAllButton',\n 'deselectAllButton',\n ]\n\n connect() {\n useNumberHelpers(this)\n super.connect()\n }\n\n async export() {\n await post(this.exportUrlValue, {\n responseKind: 'turbo-stream',\n body: {\n export: {\n contact_ids_to_operate_on: this.selectAllValue ? [] : this.checkedValue,\n order: (new URLSearchParams(window.location.search)).get('order')\n }\n }\n })\n\n this.reset()\n }\n\n activeAudienceChanged({ currentTarget }) {\n this.countValue = parseInt(currentTarget.dataset.count)\n this.reset()\n }\n\n reset() {\n this.uncheckAll()\n this.syncSelectionContainer()\n this.updateBatchButtonLabelsTo('all')\n }\n\n onContactCheckboxChange({currentTarget}) {\n if (currentTarget.checked) {\n this.checkedValue = Array.from(new Set([...this.checkedValue, currentTarget.value]))\n } else {\n this.checkedValue = this.checkedValue.filter(value => value !== currentTarget.value)\n }\n\n this.checkAllTarget.checked = this.checkedValue.length === this.countValue\n\n this.syncSelectionContainer()\n }\n\n checkAll({currentTarget}) {\n this.checkboxTargets.forEach(checkbox => {\n checkbox.checked = currentTarget.checked\n\n if (checkbox.checked) {\n this.checkedValue = Array.from(new Set([...this.checkedValue, checkbox.value]))\n } else {\n this.checkedValue = this.checkedValue.filter(value => value !== checkbox.value)\n }\n })\n\n this.syncSelectionContainer()\n }\n\n uncheckAll() {\n this.checkboxTargets.forEach(checkbox => checkbox.checked = false)\n this.checkedValue = []\n\n this.checkAllTarget.checked = false\n }\n\n removeAll() {\n this.dispatch('show', {\n target: document.getElementById('audience--radio-modal'),\n detail: {\n id: this.idValue,\n ids: this.checkedValue,\n size: this.countValue,\n contactId: this.contactIdValue,\n element: this.element,\n all: this.checkAllTarget.checked,\n }\n })\n }\n\n checkedValueChanged() {\n this.syncSelectionContainer()\n\n if (this.checkedValue.length === this.countValue || this.checkedValue.length === 0) {\n this.updateBatchButtonLabelsTo('all')\n } else {\n this.updateBatchButtonLabelsTo('selected')\n }\n }\n\n syncSelectionContainer() {\n if (this.checkAllTarget.checked && this.checkedValue.length !== this.countValue) {\n this.selectionContainerTarget.querySelector('p').innerHTML = this.translations.audience.selection.limited.replace('%{count}', this.numberWithDelimiter(this.checkedValue.length))\n this.show(this.selectionContainerTarget)\n } else {\n this.show(this.selectionContainerTarget.firstElementChild)\n this.hide(this.selectionContainerTarget.lastElementChild)\n this.hide(this.selectionContainerTarget)\n }\n }\n\n selectAll() {\n this.selectAllValue = true\n this.updateBatchButtonLabelsTo('all')\n }\n\n deselectAll() {\n this.selectAllValue = false\n this.updateBatchButtonLabelsTo('selected')\n }\n\n updateBatchButtonLabelsTo(type) {\n if(!this.hasExportButtonTarget) return\n\n this.exportButtonTarget.innerText = this.translations.audience.export.label[type]\n\n this.dispatch('selection:change', {\n target: this.element,\n detail: {\n count: type === 'all' && this.selectAllValue ? this.countValue : this.checkedValue.length,\n contactIdsToOperateOn: this.selectAllValue ? [] : this.checkedValue,\n },\n })\n }\n\n checkboxTargetConnected(element) {\n if (this.checkAllTarget.checked) {\n element.checked = true\n this.checkedValue = [...this.checkedValue, element.value]\n }\n }\n\n countValueChanged() {\n if(!this.numberWithDelimiter) {\n useNumberHelpers(this)\n }\n\n this.selectAllButtonTarget.querySelector('[data-text]').innerHTML = t.audience.selection.all.select.replace('%{count}', this.numberWithDelimiter(this.countValue))\n this.deselectAllButtonTarget.querySelector('[data-text]').innerHTML = t.audience.selection.all.deselect.replace('%{count}', this.numberWithDelimiter(this.countValue))\n }\n}\n"],"names":["radio_controller","ApplicationController","useNumberHelpers","post","currentTarget","value","checkbox","type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