/**
 * @license
 * Copyright 2023 Tyler Technologies, Inc. 
 * License: Apache-2.0
 */
import { TAB_CONSTANTS } from './tab-constants';
export class TabFoundation {
    constructor(_adapter) {
        this._adapter = _adapter;
        this._disabled = false;
        this._active = false;
        this._stretch = false;
        this._clickListener = (evt) => this._onClick(evt);
    }
    initialize() {
        this._adapter.initialize();
        this._adapter.initializeRipple();
        this._adapter.initializeIndicator();
        this._adapter.setDisabled(this._disabled);
        this._setActive(this._active);
        this._adapter.addButtonListener('click', this._clickListener);
    }
    disconnect() {
        this._adapter.destroyRipple();
        this._adapter.destroyIndicator();
        this._adapter.removeButtonListener('click', this._clickListener);
    }
    _onClick(evt) {
        if (this._disabled) {
            return;
        }
        if (!this._active) {
            this._adapter.emitHostEvent(TAB_CONSTANTS.events.INTERACTED, undefined, true);
        }
    }
    _setActive(isActive, previousIndicatorClientRect) {
        this._active = isActive;
        this._adapter.setActive(this._active);
        if (this._active) {
            this._adapter.activateIndicator(previousIndicatorClientRect);
        }
        else {
            this._adapter.deactivateIndicator();
        }
    }
    activate(previousIndicatorClientRect) {
        this._setActive(true, previousIndicatorClientRect);
    }
    deactivate() {
        this._setActive(false);
    }
    computeIndicatorBounds() {
        return this._adapter.computeIndicatorBounds();
    }
    computeDimensions() {
        const rootWidth = this._adapter.getOffsetWidth();
        const rootLeft = this._adapter.getOffsetLeft();
        const contentWidth = this._adapter.getContentOffsetWidth();
        const contentLeft = this._adapter.getContentOffsetLeft();
        return {
            contentLeft: rootLeft + contentLeft,
            contentRight: rootLeft + contentLeft + contentWidth,
            rootLeft,
            rootRight: rootLeft + rootWidth
        };
    }
    setTabIndex(value) {
        this._adapter.setTabIndex(value);
    }
    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 active() {
        return this._active;
    }
    set active(value) {
        if (this._active !== value) {
            this._setActive(value);
            this._adapter.toggleHostAttribute(TAB_CONSTANTS.attributes.ACTIVE, this._active);
        }
    }
    get stretch() {
        return this._stretch;
    }
    set stretch(value) {
        if (this._stretch !== value) {
            this._stretch = value;
            this._adapter.toggleHostAttribute(TAB_CONSTANTS.attributes.STRETCH, this._stretch);
        }
    }
}
