/**
 * @license
 * Copyright Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { TAB_CONSTANTS } from './tab-constants';
export class TabFoundation {
    constructor(_adapter) {
        this._adapter = _adapter;
        // State
        this._selected = false;
        this._disabled = false;
        this._vertical = false;
        this._stacked = false;
        this._secondary = false;
        this._inverted = false;
        this._clickListener = () => this._onClick();
        this._keydownListener = (evt) => this._onKeydown(evt);
    }
    initialize() {
        this._adapter.initialize();
        this._adapter.addInteractionListener('click', this._clickListener);
        this._adapter.addInteractionListener('keydown', this._keydownListener);
    }
    _onClick() {
        if (this._disabled || this._selected) {
            return;
        }
        this._dispatchSelectEvent();
    }
    _onKeydown(evt) {
        if (this._disabled || this._selected) {
            return;
        }
        const isSelectionKey = evt.key === ' ' || evt.key === 'Enter';
        if (isSelectionKey) {
            evt.preventDefault();
            this._adapter.animateStateLayer();
            this._dispatchSelectEvent();
        }
    }
    _dispatchSelectEvent() {
        this._adapter.emitHostEvent(TAB_CONSTANTS.events.SELECT, { bubbles: true, composed: true });
    }
    get disabled() {
        return this._disabled;
    }
    set disabled(value) {
        if (this._disabled !== value) {
            this._disabled = value;
            this._adapter.setDisabled(this._disabled);
            this._adapter.toggleHostAttribute(TAB_CONSTANTS.attributes.DISABLED, this._disabled);
        }
    }
    get selected() {
        return this._selected;
    }
    set selected(value) {
        if (this._selected !== value) {
            this._selected = value;
            this._adapter.setSelected(this._selected);
            this._adapter.animateSelected();
            this._adapter.toggleHostAttribute(TAB_CONSTANTS.attributes.SELECTED, this._selected);
        }
    }
    get vertical() {
        return this._vertical;
    }
    set vertical(value) {
        if (this._vertical !== value) {
            this._vertical = value;
            this._adapter.toggleHostAttribute(TAB_CONSTANTS.attributes.VERTICAL, this._vertical);
        }
    }
    get stacked() {
        return this._stacked;
    }
    set stacked(value) {
        if (this._stacked !== value) {
            this._stacked = value;
            this._adapter.toggleHostAttribute(TAB_CONSTANTS.attributes.STACKED, this._stacked);
        }
    }
    get secondary() {
        return this._secondary;
    }
    set secondary(value) {
        if (this._secondary !== value) {
            this._secondary = value;
            this._adapter.toggleHostAttribute(TAB_CONSTANTS.attributes.SECONDARY, this._secondary);
        }
    }
    get inverted() {
        return this._inverted;
    }
    set inverted(value) {
        if (this._inverted !== value) {
            this._inverted = value;
            this._adapter.toggleHostAttribute(TAB_CONSTANTS.attributes.INVERTED, this._inverted);
        }
    }
}
