"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.NestedCollectionState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _mobx = require("mobx");
var _NestedCollectionNodeState = require("./NestedCollectionNodeState");
var _events = require("events");
class NestedCollectionState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "container", void 0);
    (0, _defineProperty2.default)(this, "levels", void 0);
    (0, _defineProperty2.default)(this, "isFetchAllAborted", null);
    (0, _defineProperty2.default)(this, "_fetchAllTotal", undefined);
    (0, _defineProperty2.default)(this, "expandAll", true);
    (0, _defineProperty2.default)(this, "total", 0);
    (0, _defineProperty2.default)(this, "root", void 0);
    (0, _defineProperty2.default)(this, "query", void 0);
    (0, _defineProperty2.default)(this, "sequences", void 0);
    (0, _defineProperty2.default)(this, "events", new _events.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.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;
    }
    (0, _mobx.makeObservable)(this, {
      total: _mobx.observable.ref
    });
  }
  init() {
    return () => {
      const disposeListeners = this.events.listeners('dispose');
      this.events.removeAllListeners('dispose');
      return disposeListeners.forEach(d => d == null ? void 0 : d());
    };
  }
}
exports.NestedCollectionState = NestedCollectionState;
//# sourceMappingURL=NestedCollectionState.js.map