"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.LayoutSwitchState = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _bexCore = require("@wix/bex-core");
var _mobx = require("mobx");
var _EditableTable = require("./EditableTable");
var _GridState = require("./GridState");
var _TableState = require("./TableState");
var _ToolbarCollectionState = require("./ToolbarCollectionState");
var _ViewTypeState = require("./ViewTypeState");
const componentType = 'LayoutSwitch';
class LayoutSwitchState {
  get viewType() {
    return this.viewTypeState.viewType;
  }
  set viewType(v) {
    (0, _mobx.runInAction)(() => {
      this.viewTypeState.viewType = v;
    });
  }
  get options() {
    return this.viewTypeState.options;
  }
  constructor(params) {
    (0, _defineProperty2.default)(this, "collection", void 0);
    (0, _defineProperty2.default)(this, "toolbar", void 0);
    (0, _defineProperty2.default)(this, "containerOverrides", void 0);
    (0, _defineProperty2.default)(this, "tableState", void 0);
    (0, _defineProperty2.default)(this, "gridState", void 0);
    (0, _defineProperty2.default)(this, "spreadsheetState", void 0);
    (0, _defineProperty2.default)(this, "viewTypeState", void 0);
    (0, _defineProperty2.default)(this, "initTask", new _bexCore.TaskState());
    this.collection = params.collection;
    this.containerOverrides = params.containerOverrides;
    this.toolbar = new _ToolbarCollectionState.ToolbarCollectionState({
      componentType,
      collection: this.collection,
      container: params.container,
      reportBi: biParams => params.container.reportBi({
        ...biParams,
        params: {
          ...biParams.params,
          componentStatus: this.viewTypeState.viewType
        }
      })
    });
    this.tableState = params.table ? new _TableState.TableState({
      collection: this.collection,
      container: params.container,
      toolbar: this.toolbar
    }) : undefined;
    this.gridState = params.grid ? new _GridState.GridState({
      collection: this.collection,
      container: params.container,
      toolbar: this.toolbar
    }) : undefined;
    this.spreadsheetState = params.spreadsheet ? new _EditableTable.EditableTableState({
      collection: this.collection,
      container: params.container,
      toolbar: this.toolbar,
      ...params.spreadsheet
    }) : undefined;
    const enabledLayouts = [params.table ? 'table' : null, params.grid ? 'grid' : null, params.spreadsheet ? 'spreadsheet' : null].filter(Boolean);
    this.viewTypeState = new _ViewTypeState.ViewTypeState({
      container: params.container,
      dataCapsule: this.toolbar.dataCapsule,
      componentType,
      collection: this.collection,
      options: enabledLayouts
    });
    this.toolbar.layoutState = this;
    (0, _mobx.makeObservable)(this, {
      viewType: _mobx.computed,
      options: _mobx.computed
    });
  }
  init() {
    const {
      viewTypeState,
      initTask
    } = this;
    viewTypeState.init();
    initTask.runOnce(async () => {
      viewTypeState.initTask.runOnce();
      await viewTypeState.initTask.status.promise;
    });
  }
}
exports.LayoutSwitchState = LayoutSwitchState;
//# sourceMappingURL=LayoutSwitchState.js.map