import { DataSourceType } from "../../../_utils/formKeyType";
import { uuid } from "../../../_utils/utils";
export 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 
 */
export 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;
}
export function getNewKeyByApiParams(apiParams) {
  var result = '';
  if (apiParams.length) {
    apiParams.forEach(function (item) {
      result += item.id;
    });
  }
  return result;
}
export var getInitStateKey = function getInitStateKey(formKey, data) {
  return {
    id: uuid(),
    formKey: formKey,
    data: data,
    treeData: []
  };
};

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