/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { BANNER_CONSTANTS } from './banner-constants';
export class BannerFoundation {
    constructor(_adapter) {
        this._adapter = _adapter;
        this._dismissed = false;
        this._canDismiss = true;
        this._dismissBanner = () => this._dismiss();
    }
    connect() {
        this._addDismissEventListener();
    }
    disconnect() {
        this._removeDismissEventListener();
    }
    _dismiss() {
        this.dismissed = true;
    }
    _syncDismissedState() {
        if (this.dismissed) {
            this._setDismissedClass();
            this._adapter.emitHostEvent(BANNER_CONSTANTS.events.DISMISSED);
        }
        else {
            this._setUndissmissedClass();
            this._adapter.emitHostEvent(BANNER_CONSTANTS.events.UNDISMISSED);
        }
    }
    _setUndissmissedClass() {
        this._adapter.removeRootClass(BANNER_CONSTANTS.classes.DISMISSED);
    }
    _setDismissedClass() {
        this._adapter.addRootClass(BANNER_CONSTANTS.classes.DISMISSED);
    }
    _syncCanDismissState() {
        if (this.canDismiss) {
            this._adapter.removeDismissButtonAttribute(BANNER_CONSTANTS.attributes.HIDDEN);
        }
        else {
            this._adapter.addDismissButtonAttribute(BANNER_CONSTANTS.attributes.HIDDEN);
        }
    }
    _addDismissEventListener() {
        this._adapter.addDismissEventListener('click', this._dismissBanner);
    }
    _removeDismissEventListener() {
        this._adapter.removeDismissEventListener('click', this._dismissBanner);
    }
    get dismissed() {
        return !!this._dismissed;
    }
    set dismissed(val) {
        if (this.dismissed === !!val) {
            return;
        }
        this._dismissed = !!val;
        this._syncDismissedState();
    }
    get canDismiss() {
        return !!this._canDismiss;
    }
    set canDismiss(val) {
        if (this._canDismiss === !!val) {
            return;
        }
        this._canDismiss = !!val;
        this._syncCanDismissState();
    }
}
