"use strict";

exports.__esModule = true;
exports.getChangePactAddressObj = getChangePactAddressObj;
exports.getPbiDataItemData = getPbiDataItemData;
var _comFn = require("../../cTreeDataRelation-setter/comFn");
var _formKeyType = require("../../../_utils/formKeyType");
var _lodash = require("lodash");
var _type = require("../../../../src/utils/pactList/type");
function getPbiDataItemData(list) {
  var result = [];
  list.forEach(function (item) {
    var treeItem = (0, _comFn.createTreeRelationItem)({
      name: "" + item.name,
      type: item.type,
      disabled: item.editable !== undefined ? !item.editable : true,
      value: item.value,
      required: item.required,
      formKey: _formKeyType.DataSourceType.defaultType
    });

    // 补充精度
    if (item.decimals !== undefined) {
      treeItem.decimals = item.decimals;
    }

    // 处理元组
    if (item.type === _type.PactNameType.tuple || item.type === _type.PactNameType.tupleList) {
      treeItem.formKey = _formKeyType.DataSourceType.tupleType;
      treeItem.addable = item.addable !== undefined ? item.addable : 0;
      if (item.components.length) {
        treeItem.components = getPbiDataItemData(item.components);
      } else {
        treeItem.components = [];
        treeItem.addable = 0;
        // if (item.value) {
        //     treeItem.data = getValidString(item.value)
        // }
      }
      // 是元组类型的value存在都需要处理
      if (item.value) {
        treeItem.data = getTreeItemValueByItem(item.value);
      }
    }
    result.push(treeItem);
  });
  return result;
}
function getTreeItemValueByItem(list) {
  var result = [];
  if ((0, _lodash.isArray)(list)) {
    list.forEach(function (item) {
      var res = getPbiDataItemData(item);
      result.push(res);
    });
  }
  return result;
}
function getChangePactAddressObj(list, pactAddress) {
  var result = null;
  var obj = (0, _lodash.cloneDeep)(pactAddress);
  if (obj) {
    list.forEach(function (item) {
      var key = item.key,
        value = item.value;
      obj[key] = value;
    });
    result = obj;
  }
  return result;
}