import { addResizeObserver } from '@wix/bex-core';
export class ToolbarLeftGroupState {
    constructor(params) {
        this._element = null;
        this._tabsWidthTimeout = null;
        this._handleResize = () => {
            const element = this._element;
            if (!element) {
                return;
            }
            if (this.mode === 'tabs') {
                if (this._tabsWidthTimeout) {
                    clearTimeout(this._tabsWidthTimeout);
                }
                this._tabsWidthTimeout = setTimeout(() => {
                    this._tabsWidthTimeout = null;
                    if (!this._element)
                        return;
                    const tabsState = this._getTabsState?.();
                    tabsState?.responsive.setAvailableWidth(this._element.clientWidth);
                }, 300);
            }
            this._responsive._scheduleRecompute();
        };
        this._responsive = params.responsive;
        this.mode = params.mode;
        this.minWidth = params.minWidth;
        this._getTabsState = params.getTabsState;
    }
    getExcessWidth() {
        if (!this._element) {
            return 0;
        }
        return Math.max(0, this._element.clientWidth - this.minWidth);
    }
    init(element) {
        this._element = null;
        if (!element) {
            return () => { };
        }
        this._element = element;
        const disposer = addResizeObserver(element, this._handleResize);
        return () => {
            disposer?.();
            if (this._tabsWidthTimeout) {
                clearTimeout(this._tabsWidthTimeout);
                this._tabsWidthTimeout = null;
            }
            this._element = null;
        };
    }
}
//# sourceMappingURL=ToolbarLeftGroupState.js.map