import _createClass from "@babel/runtime/helpers/createClass";
import { makeAutoObservable } from 'mobx';
import { uniqueId } from '../utils';
function isComplexProp(prop) {
  return prop.value && typeof prop.value === 'object';
}
var Prop = /*#__PURE__*/function () {
  function Prop(parent, _value, name) {
    var _this = this;
    this.id = uniqueId('prop');
    this.owner = void 0;
    this.parent = void 0;
    this.name = void 0;
    this.value = void 0;
    this.setValue = function (value, subName) {
      if (subName) {
        if (isComplexProp(_this.value)) {
          _this.value.value[subName] = value;
        } else {
          console.error(_this.name + " \u4E0D\u5B58\u5728\u4E00\u4E2A\u540D\u4E3A " + subName + " \u7684\u5B50\u5B57\u6BB5");
        }
      } else {
        _this.value = value;
      }
      _this.project.designer.rerender();
    };
    this.getValue = function (subName) {
      if (!subName) {
        return _this["export"]();
      } else {
        if (isComplexProp(_this.value)) {
          return _this.value.value[subName];
        } else {
          console.error(_this.name + " \u4E0D\u5B58\u5728\u4E00\u4E2A\u540D\u4E3A " + subName + " \u7684\u5B50\u5B57\u6BB5");
          return '';
        }
      }
    };
    makeAutoObservable(this, {
      id: false,
      parent: false,
      owner: false,
      name: false,
      project: false
    });
    this.parent = parent;
    this.owner = parent.owner;
    this.name = name;
    this.value = _value;
  }
  var _proto = Prop.prototype;
  _proto["export"] = function _export() {
    return this.value;
  };
  _createClass(Prop, [{
    key: "project",
    get: function get() {
      return this.owner.owner.project;
    }
  }]);
  return Prop;
}();
export { Prop as default };