import { ValueBox, withoutDefaults } from '@wix/bex-core';
import { cairoFiltersPanelUsed } from '@wix/bex-core/bi';
import { action, computed, makeObservable } from 'mobx';
import { createRef } from 'react';
export class CollectionToolbarFiltersState {
    constructor(params) {
        this.panelTitle = new ValueBox(undefined);
        this.totalInlineFilters = new ValueBox(null);
        this.filterElements = new ValueBox([]);
        this.moreFiltersButtonRef = createRef();
        this.onFiltersButtonClick = action(() => {
            const actionStartTime = performance.now();
            const { reportBi } = this.toolbar;
            const isOpened = this.toolbar.panels.toggleSidePanel('filters');
            // to be called after the panel is opened/closed and call stack is cleared
            window.setTimeout(() => {
                reportBi(withoutDefaults(cairoFiltersPanelUsed)({
                    ...this.toolbar._commonDynamicBiParams(),
                    isOpened,
                    origin: 'Filter Button',
                    feature: 'Filter',
                    timeFromAction: Math.round(performance.now() - actionStartTime),
                }));
            });
        });
        this.toolbar = params.toolbar;
        makeObservable(this, {
            panelFilterElements: computed,
            panelFilters: computed,
        });
    }
    get panelFilterElements() {
        const { totalInlineFilters: { value: totalInlineFilters }, filterElements: { value: filterElements }, } = this;
        return totalInlineFilters != null
            ? filterElements.slice(totalInlineFilters)
            : [];
    }
    get panelFilters() {
        return this.panelFilterElements.map((element) => element.props.filter);
    }
}
//# sourceMappingURL=CollectionToolbarFiltersState.js.map