import { getValidString, uuid } from "../../../_utils/utils";
import { TreeDataRelationService } from "../../../_utils/treeDataRelationFn/treeDataRelationService";
import { DataSourceType, getRelationList } from "../../../_utils/formKeyType";
import { isNumber } from "lodash";
import { ComponentName } from "../../../_utils/treeDataRelationFn/type";
var treeDataRelationService = new TreeDataRelationService();
function comHandleTreeDataFn(treeData) {
  return treeDataRelationService.createRelationDataByTreeData(treeData);
}
export function getPageTreeDataRelation() {
  var treeData = treeDataRelationService.getFormStateDataBySchema();
  return comHandleTreeDataFn(treeData);
}
export function getDataSourceDataRelation() {
  var treeData = treeDataRelationService.getDataSourceBySchema();
  return comHandleTreeDataFn(treeData);
}
export function getDictionaryRelation() {
  var treeData = treeDataRelationService.getDictionaryRelation();
  return comHandleTreeDataFn(treeData);
}
export function getEngineRuleRelation() {
  var treeData = treeDataRelationService.getEngineRuleRelation();
  return comHandleTreeDataFn(treeData);
}
export function getLoopDataSelectedRelation() {
  var treeData = treeDataRelationService.getLoopDataSelectedRelation();
  return comHandleTreeDataFn(treeData);
}
export function getCustomStateRelation() {
  var treeData = treeDataRelationService.getCustomStateBySchema();
  return comHandleTreeDataFn(treeData);
}
export function getModalDialogRelation() {
  var treeData = treeDataRelationService.getModalDialogRelation();
  return comHandleTreeDataFn(treeData);
}
export function getWalletConnectRelation() {
  var treeData = treeDataRelationService.getWalletConnectRelation();
  return comHandleTreeDataFn(treeData);
}
export function getUrlRelation() {
  var treeData = treeDataRelationService.getUrlRelation();
  return comHandleTreeDataFn(treeData);
}
export function getStorageDataRelation() {
  var treeData = treeDataRelationService.getStorageDataRelation();
  return comHandleTreeDataFn(treeData);
}
export function createTreeRelationItem(config) {
  var name = config.name,
    disabled = config.disabled,
    value = config.value,
    required = config.required,
    formKey = config.formKey,
    type = config.type;
  return {
    id: uuid(),
    name: name || '',
    type: type || '',
    disabled: disabled || false,
    data: getValidString(value),
    required: required ? isNumber(required) ? required : parseInt(required) : 0,
    treeData: [],
    formKey: formKey ? formKey : DataSourceType.defaultType
  };
}
export function getRelationListByProps(props) {
  var _props$field, _props$field$extraPro;
  var list = getRelationList();
  if (props !== null && props !== void 0 && (_props$field = props.field) !== null && _props$field !== void 0 && (_props$field$extraPro = _props$field.extraProps) !== null && _props$field$extraPro !== void 0 && _props$field$extraPro.componentName) {
    var comList = [ComponentName.ModalDefault, ComponentName.Drawer, ComponentName.Modal];
    var name = props.field.extraProps.componentName;
    if (comList.includes(name)) {
      var mate = list.filter(function (item) {
        return item.value === DataSourceType.materielType;
      }) || [];
      if (mate.length === 0) {
        list.push({
          label: "物料数据",
          value: DataSourceType.materielType
        });
      }
    }
  }
  return list;
}