import { getComponentId, handleMaterialUUID } from "../../utils";
import { ComponentName, TreeType } from "../type";
function isButtonComponent(props) {
  var result = false;
  if (props.componentName === ComponentName.Button) {
    return true;
  }
  if (props.componentName === ComponentName.FormItem && props.children.length) {
    var childrenComponentNameList = props.children.map(function (item) {
      return item.componentName;
    });
    return childrenComponentNameList.includes(ComponentName.Button);
  }
  return result;
}

/**
 * 处理登录表单
 * @param item
 * @returns
 */
export function handleCLogin(item) {
  var resultData = [];
  var result = {
    label: item.props.nodeKey || 'login',
    key: getComponentId(item.props),
    type: TreeType.login,
    children: []
  };
  if (item.children && item.children.length) {
    item.children.forEach(function (child) {
      if (!isButtonComponent(child)) {
        var _result$children;
        var label = child.props.name ? handleMaterialUUID(child.props.name) : '未标识';
        (_result$children = result.children) === null || _result$children === void 0 ? void 0 : _result$children.push({
          label: label,
          key: getComponentId(child.props),
          type: TreeType.loginFormItem,
          componentName: child.children[0].componentName // 默认一个项目中只有一个
        });
      }
    });
  }
  resultData.push(result);
  return resultData;
}