"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.TableGridSwitchState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _bexCore = require("@wix/bex-core");
var _TableState = require("./TableState");
var _GridState = require("./GridState");
var _mobx = require("mobx");
var _ToolbarCollectionState = require("./ToolbarCollectionState");
var _ViewTypeState = require("./ViewTypeState");
const componentType = 'TableGridSwitch';
class TableGridSwitchState {
  constructor(params) {
    (0, _defineProperty2.default)(this, "collection", void 0);
    (0, _defineProperty2.default)(this, "container", void 0);
    (0, _defineProperty2.default)(this, "containerOverrides", void 0);
    (0, _defineProperty2.default)(this, "initTask", new _bexCore.TaskState());
    (0, _defineProperty2.default)(this, "gridState", void 0);
    (0, _defineProperty2.default)(this, "tableState", void 0);
    (0, _defineProperty2.default)(this, "viewTypeState", void 0);
    this.container = params.container;
    this.containerOverrides = params.containerOverrides;
    this.collection = params.collection;
    this.tableState = new _TableState.TableState({
      collection: this.collection,
      container: this.container,
      toolbar: new _ToolbarCollectionState.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.GridState({
      collection: this.collection,
      container: this.container,
      toolbar: this.tableState.toolbar
    });
    this.viewTypeState = new _ViewTypeState.ViewTypeState({
      container: this.container,
      dataCapsule: this.toolbar.dataCapsule,
      componentType,
      collection: this.collection
    });
    (0, _mobx.makeObservable)(this, {
      viewType: _mobx.computed
    });
  }
  get viewType() {
    return this.viewTypeState.viewType;
  }
  set viewType(viewType) {
    (0, _mobx.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;
    });
  }
}
exports.TableGridSwitchState = TableGridSwitchState;
//# sourceMappingURL=TableGridSwitchState.js.map