"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 _utils = require("../utils");
var SettingField = exports["default"] = /*#__PURE__*/function () {
  function SettingField(owner, config) {
    var _this = this,
      _this$config$fields;
    this.owner = void 0;
    this.config = void 0;
    this.id = void 0;
    this.fields = [];
    this.getValue = function () {
      var value;
      var _this$PropKey = _this.PropKey,
        name = _this$PropKey.name,
        subName = _this$PropKey.subName;
      if (!_this.isExtra) {
        var _this$owner$getProp;
        value = (_this$owner$getProp = _this.owner.getProp(name)) === null || _this$owner$getProp === void 0 ? void 0 : _this$owner$getProp.getValue(subName);
      } else {
        var _this$owner$getExtraP;
        value = (_this$owner$getExtraP = _this.owner.getExtraProp(name)) === null || _this$owner$getExtraP === void 0 ? void 0 : _this$owner$getExtraP.getValue(subName);
      }
      if ((0, _utils.isJsRunFunction)(value)) {
        var tempFunc = (0, _utils.transformStringToFunction)(value.value);
        return tempFunc(_this.owner.owner);
      } else {
        return value;
      }
    };
    this.setValue = function (value) {
      var _this$PropKey2 = _this.PropKey,
        name = _this$PropKey2.name,
        subName = _this$PropKey2.subName;
      if (!_this.isExtra) {
        var _this$owner$getProp2;
        (_this$owner$getProp2 = _this.owner.getProp(name)) === null || _this$owner$getProp2 === void 0 ? void 0 : _this$owner$getProp2.setValue(value, subName);
      } else {
        var _this$owner$getExtraP2;
        (_this$owner$getExtraP2 = _this.owner.getExtraProp(name)) === null || _this$owner$getExtraP2 === void 0 ? void 0 : _this$owner$getExtraP2.setValue(value, subName);
      }
    };
    this.owner = owner;
    this.config = config;
    this.id = (0, _utils.uniqueId)('settingField');
    if ((_this$config$fields = this.config.fields) !== null && _this$config$fields !== void 0 && _this$config$fields.length) {
      this.fields = this.config.fields.map(function (item) {
        return new SettingField(_this.owner, item);
      });
    }
  }
  (0, _createClass2["default"])(SettingField, [{
    key: "isGroup",
    get: function get() {
      return this.config.type === 'group';
    }
  }, {
    key: "title",
    get: function get() {
      return this.config.title;
    }
  }, {
    key: "name",
    get: function get() {
      return this.config.name;
    }
  }, {
    key: "parentName",
    get: function get() {
      return this.config.parentName;
    }
  }, {
    key: "setters",
    get: function get() {
      return this.config.setters;
    }
  }, {
    key: "isExtra",
    get: function get() {
      return !this.isGroup && this.config.isExtra === true;
    }
  }, {
    key: "PropKey",
    get: function get() {
      var name = this.parentName ? this.parentName : this.name;
      var subName = this.parentName ? this.name : undefined;
      return {
        name: name,
        subName: subName
      };
    }
  }]);
  return SettingField;
}();