import { TaskState, } from '@wix/bex-core';
import { TableState } from './TableState';
import { GridState } from './GridState';
import { computed, makeObservable, runInAction } from 'mobx';
import { ToolbarCollectionState } from './ToolbarCollectionState';
import { ViewTypeState } from './ViewTypeState';
const componentType = 'TableGridSwitch';
export class TableGridSwitchState {
    constructor(params) {
        this.initTask = new TaskState();
        this.container = params.container;
        this.containerOverrides = params.containerOverrides;
        this.collection = params.collection;
        this.tableState = new TableState({
            collection: this.collection,
            container: this.container,
            toolbar: new ToolbarCollectionState({
                componentType,
                collection: this.collection,
                container: this.container,
                reportBi: (biParams) => this.container.reportBi({
                    ...biParams,
                    params: {
                        ...biParams.params,
                        componentStatus: this.viewTypeState.viewType,
                    },
                }),
            }),
        });
        this.gridState = new GridState({
            collection: this.collection,
            container: this.container,
            toolbar: this.tableState.toolbar,
        });
        this.viewTypeState = new ViewTypeState({
            container: this.container,
            dataCapsule: this.toolbar.dataCapsule,
            componentType,
            collection: this.collection,
        });
        makeObservable(this, {
            viewType: computed,
        });
    }
    get viewType() {
        return this.viewTypeState.viewType;
    }
    set viewType(viewType) {
        runInAction(() => {
            this.viewTypeState.viewType = viewType;
        });
    }
    get toolbar() {
        return this.tableState.toolbar;
    }
    init() {
        const { viewTypeState, initTask } = this;
        viewTypeState.init();
        initTask.runOnce(async () => {
            viewTypeState.initTask.runOnce();
            await viewTypeState.initTask.status.promise;
        });
    }
}
//# sourceMappingURL=TableGridSwitchState.js.map