"use strict";

exports.__esModule = true;
exports.getDialogParamsByTreeData = getDialogParamsByTreeData;
exports.getInitStateKey = void 0;
exports.getNewKeyByApiParams = getNewKeyByApiParams;
exports.getTreeDataNum = getTreeDataNum;
exports.handleStringToRequest = void 0;
var _formKeyType = require("../../../_utils/formKeyType");
var _utils = require("../../../_utils/utils");
function getTreeDataNum(treeData) {
  var result = 0;
  treeData.forEach(function (item) {
    if (item.children.length) {
      result += getTreeDataNum(item.children);
    } else {
      result++;
    }
  });
  return result;
}

/**
 * 从schema中找到当前弹框的参数
 * @param treeData 
 */
function getDialogParamsByTreeData(treeData) {
  var _treeData$0$children;
  var result = [];

  // 找到就返回了
  if (treeData.length && treeData[0].apiParams) {
    result = treeData[0].apiParams;
    return result;
  }
  if (treeData.length && (_treeData$0$children = treeData[0].children) !== null && _treeData$0$children !== void 0 && _treeData$0$children.length) {
    result = getDialogParamsByTreeData(treeData[0].children);
  }
  return result;
}
function getNewKeyByApiParams(apiParams) {
  var result = '';
  if (apiParams.length) {
    apiParams.forEach(function (item) {
      result += item.id;
    });
  }
  return result;
}
var getInitStateKey = exports.getInitStateKey = function getInitStateKey(formKey, data) {
  return {
    id: (0, _utils.uuid)(),
    formKey: formKey,
    data: data,
    treeData: []
  };
};

/**
 * 兼容代码之前的url和content可能是string类型
 * @param value 
 */
var handleStringToRequest = exports.handleStringToRequest = function handleStringToRequest(value) {
  var result = getInitStateKey(_formKeyType.DataSourceType.defaultType, '');
  if (value && typeof value === 'string') {
    result = getInitStateKey(_formKeyType.DataSourceType.defaultType, value);
  } else if ((value === null || value === void 0 ? void 0 : value.formKey) !== undefined) {
    result = value;
  }
  return result;
};