"use strict";

exports.__esModule = true;
exports.handleCLogin = handleCLogin;
var _utils = require("../../utils");
var _type = require("../type");
function isButtonComponent(props) {
  var result = false;
  if (props.componentName === _type.ComponentName.Button) {
    return true;
  }
  if (props.componentName === _type.ComponentName.FormItem && props.children.length) {
    var childrenComponentNameList = props.children.map(function (item) {
      return item.componentName;
    });
    return childrenComponentNameList.includes(_type.ComponentName.Button);
  }
  return result;
}

/**
 * 处理登录表单
 * @param item
 * @returns
 */
function handleCLogin(item) {
  var resultData = [];
  var result = {
    label: item.props.nodeKey || 'login',
    key: (0, _utils.getComponentId)(item.props),
    type: _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 ? (0, _utils.handleMaterialUUID)(child.props.name) : '未标识';
        (_result$children = result.children) === null || _result$children === void 0 ? void 0 : _result$children.push({
          label: label,
          key: (0, _utils.getComponentId)(child.props),
          type: _type.TreeType.loginFormItem,
          componentName: child.children[0].componentName // 默认一个项目中只有一个
        });
      }
    });
  }
  resultData.push(result);
  return resultData;
}