import { makeObservable, observable } from 'mobx';
import { NestedCollectionNodeState } from './NestedCollectionNodeState';
import { EventEmitter } from 'events';
export class NestedCollectionState {
    constructor(params) {
        this.isFetchAllAborted = null;
        this._fetchAllTotal = undefined;
        this.expandAll = true;
        this.total = 0;
        this.events = new EventEmitter();
        const { container } = params;
        this.container = container;
        this.sequences = params.sequences;
        const rootLevelDescriptor = params.levels[0];
        this.levels = params.levels;
        this.query = params.query;
        this.root = new NestedCollectionNodeState({
            nestedCollection: this,
            parentNode: null,
            parent: null,
            levelDescriptor: rootLevelDescriptor,
            nodeCollection: params.nodeCollection,
        });
        const parentFilter = this.root.parentFilter;
        if (parentFilter != null) {
            parentFilter.setValue(['null']);
            parentFilter.persistent = true;
        }
        makeObservable(this, {
            total: observable.ref,
        });
    }
    init() {
        return () => {
            const disposeListeners = this.events.listeners('dispose');
            this.events.removeAllListeners('dispose');
            return disposeListeners.forEach((d) => d?.());
        };
    }
}
//# sourceMappingURL=NestedCollectionState.js.map