"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
var _mobx = require("mobx");
var _utils = require("../utils");
function isComplexProp(prop) {
  return prop.value && typeof prop.value === 'object';
}
var Prop = exports["default"] = /*#__PURE__*/function () {
  function Prop(parent, _value, name) {
    var _this = this;
    this.id = (0, _utils.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 '';
        }
      }
    };
    (0, _mobx.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;
  };
  (0, _createClass2["default"])(Prop, [{
    key: "project",
    get: function get() {
      return this.owner.owner.project;
    }
  }]);
  return Prop;
}();