{"version":3,"file":"contact_controller-BMtfftNx.js","sources":["../../../app/javascript/controllers/audience/contact_controller.js"],"sourcesContent":["import ApplicationController from '../application_controller'\n\nexport default class extends ApplicationController {\n static values = {\n url: String,\n state: String,\n navigate: { type: Boolean, default: false },\n newEventUrl: String,\n }\n\n static targets = [\n 'link',\n 'destroyed',\n 'checkbox',\n 'markAsActive',\n ]\n\n static classes = ['active']\n\n initialize() {\n super.initialize()\n this.popStateListener = this.popStateListener.bind(this)\n }\n\n connect() {\n super.connect()\n\n if(this.stateValue === 'draft') {\n this.activate()\n }\n\n if(window.location.pathname === this.urlValue) {\n this.nextTick(() => this.activate())\n }\n\n if(this.navigateValue) {\n this.nextTick(() => {\n this.element.removeAttribute('data-audience--contact-navigate-value')\n this.linkTarget.click()\n })\n }\n\n window.addEventListener('popstate', this.popStateListener)\n }\n\n disconnect() {\n super.disconnect()\n window.removeEventListener('popstate', this.popStateListener)\n }\n\n popStateListener() {\n if(this.stateValue === 'draft') {\n return this.element.remove()\n }\n }\n\n clickLink({ target }) {\n if(target === this.checkboxTarget) return\n this.linkTarget.click()\n }\n\n markAsActive() {\n this.activate()\n }\n\n activate() {\n document\n .querySelectorAll(`.audience--contact-card`)\n .forEach(contactCard => contactCard.removeAttribute('data-active'))\n\n if(this.stateValue !== 'draft') {\n document\n .querySelector('.audience--contact-card[data-audience--contact-state-value=\"draft\"]')\n ?.remove()\n }\n\n this.element.setAttribute('data-active', true)\n\n if(this.stateValue !== 'draft') {\n document.getElementById('new_event').href = this.newEventUrlValue\n }\n }\n\n destroyedTargetConnected() {\n this.remove()\n }\n\n markAsActiveTargetConnected() {\n this.activate()\n this.markAsActiveTarget.remove()\n }\n\n remove() {\n this.element.remove()\n\n if(window.location.pathname === this.urlValue) {\n this.nextTick(() => {\n history.go(-1)\n }, 300)\n }\n }\n\n // private\n\n get active() {\n return this.element.hasAttribute('data-active')\n }\n\n get inactive() {\n return !this.active\n }\n}\n"],"names":["contact_controller","ApplicationController","target","contactCard","_a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