{"version":3,"file":"link_controller-Gnnrw_z_.js","sources":["../../../app/javascript/controllers/audience/link_controller.js"],"sourcesContent":["import ApplicationController from \"../application_controller\"\n\nexport default class extends ApplicationController {\n static values = {\n path: String,\n }\n\n static targets = [\n 'link',\n 'count',\n ]\n\n initialize() {\n super.initialize()\n this.popStateListener = this.popStateListener.bind(this)\n }\n\n connect() {\n if (window.location.pathname === this.pathValue) {\n this.markAsActive()\n }\n\n window.addEventListener('popstate', this.popStateListener)\n super.connect()\n }\n\n disconnect() {\n window.removeEventListener('popstate', this.popStateListener)\n super.disconnect()\n }\n\n popStateListener() {\n if (window.location.pathname === this.pathValue) {\n this.markAsActive()\n }\n }\n\n markAsActive() {\n document.querySelector('.audience--link.active')?.classList?.remove('active')\n this.addClass(this.linkTarget, 'active')\n\n this.dispatch('activated', {\n detail: {\n path: this.pathValue,\n count: this.element.dataset.count,\n exportUrl: this.element.dataset.exportPath,\n batchUrl: this.element.dataset.batchPath,\n batchUpdateUrl: this.element.dataset.batchUpdatePath,\n }\n })\n }\n\n countTargetConnected() {\n const { value } = this.countTarget.dataset\n const currentCount = this.element.dataset.count\n\n if(value === 'decrement') {\n this.element.dataset.count = parseInt(currentCount) - 1\n } else if(value === 'increment') {\n this.element.dataset.count = parseInt(currentCount) + 1\n } else {\n this.element.dataset.count = value\n }\n\n this.countTarget.remove()\n\n if (window.location.pathname.startsWith(this.pathValue)) {\n this.dispatch('activated', {\n detail: {\n path: this.pathValue,\n count: this.element.dataset.count,\n }\n })\n }\n }\n}\n"],"names":["link_controller","ApplicationController","_b","_a","value","currentCount","__publicField"],"mappings":"uNAEe,MAAKA,UAASC,CAAsB,CAUjD,YAAa,CACX,MAAM,WAAU,EAChB,KAAK,iBAAmB,KAAK,iBAAiB,KAAK,IAAI,CAC3D,CAEE,SAAU,CACJ,OAAO,SAAS,WAAa,KAAK,WACpC,KAAK,aAAY,EAGnB,OAAO,iBAAiB,WAAY,KAAK,gBAAgB,EACzD,MAAM,QAAO,CACjB,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