"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Store = void 0;

var _mobx = require("mobx");

var debug = require('debug')('worker:mobx');

var Store =
/** @class */
function () {
  function Store() {
    this.hoveredMeta = ''; // hover的元组件Id

    this.clickedMeta = ''; // 点击的元组件Id

    this.clickedGroup = ''; // 点击的元组件组Id

    this.clickedFloor = ''; // 点击的楼层Id

    this.textSelection = null; // 文本元组件选中区域

    this.MPageData = []; // 楼层数据

    (0, _mobx.makeObservable)(this, {
      hoveredMeta: _mobx.observable,
      clickedMeta: _mobx.observable,
      clickedGroup: _mobx.observable,
      clickedFloor: _mobx.observable,
      setState: _mobx.action.bound
    });
  }
  /** 修改状态 */


  Store.prototype.setState = function (data) {
    var _this = this;

    debug('magicDesign state', data);
    var propertyList = Object.getOwnPropertyNames(data);
    propertyList.forEach(function (field) {
      _this[field] = data[field];
    });
  };
  /**
   *根据groupId 获取楼层Id
   * @param id groupId
   */


  Store.prototype.getFloorIdByGroupId = function (id) {
    var componentFloor = this.MPageData.find(function (floor) {
      var _a;

      var group = (_a = floor.groupSource) === null || _a === void 0 ? void 0 : _a.find(function (grp) {
        return grp.id === id;
      });
      return !!group;
    });
    return componentFloor === null || componentFloor === void 0 ? void 0 : componentFloor.id;
  };
  /**
   * 根据元组件Id 获取 楼层Id
   * @param id
   * @returns
   */


  Store.prototype.getFloorIdByMetaId = function (id) {
    var componentFloor = this.MPageData.find(function (floor) {
      var floorStr = JSON.stringify(floor);
      return floorStr.includes(id);
    });
    return componentFloor.id;
  };

  Store.prototype.getFloorInfo = function () {
    var _this = this;

    var componentFloor = this.MPageData.find(function (floor) {
      return floor.id === _this.clickedFloor;
    });
    return componentFloor;
  };

  return Store;
}();

exports.Store = Store;