import { Controller } from '@hotwired/stimulus';
// Footer consent bar for the onboarding address autocomplete. Shares the exact
// same consent flag (`mapbox-consent` in localStorage) and signal
// (`mapbox-consent-given` window event) as the map embed on the offer detail
// page, so consenting in either place enables both. The bar starts hidden and is
// only revealed when consent is still missing.
export default class default_1 extends Controller {
    constructor() {
        super(...arguments);
        this.onConsent = () => this.hide();
    }
    connect() {
        if ('true' === localStorage.getItem('mapbox-consent')) {
            return;
        }
        this.element.classList.remove('hidden');
        window.addEventListener('mapbox-consent-given', this.onConsent);
    }
    disconnect() {
        window.removeEventListener('mapbox-consent-given', this.onConsent);
    }
    accept() {
        localStorage.setItem('mapbox-consent', 'true');
        // The map embed's controller and the autofill controller both listen for
        // this; the bar hides itself via the same listener.
        window.dispatchEvent(new CustomEvent('mapbox-consent-given'));
    }
    toggleInfo() {
        if (this.hasInfoTarget) {
            this.infoTarget.classList.toggle('hidden');
        }
    }
    hide() {
        this.element.classList.add('hidden');
    }
}
default_1.targets = ['info'];
