import { t } from "../../src/locale";
import snippets from "./snippets";
export var hideProp = function hideProp() {
  return false;
};
function getPageTarge(item) {
  var result;
  if (item.isPage || item.node.isPage) {
    result = item;
  } else if (item.node.parent) {
    result = getPageTarge(item.node.parent);
  }
  return result;
}
function isFormItemChild(name) {
  var formItemChildNameList = ['Input'];
  if (formItemChildNameList.includes(name)) {
    return true;
  } else if (name.startsWith('Input')) {
    return true;
  }
  return false;
}
export default {
  snippets: snippets,
  componentName: 'FormPro',
  title: t('from-pro.key_ZUMId2yEBKJk'),
  category: t('from-pro.key_EULbdEiqa9NW'),
  "group": t('from-pro.key_9e45sq2dC67N'),
  props: [],
  configure: {
    component: {
      isContainer: true
    },
    props: [],
    supports: {
      events: false,
      style: true,
      "loop": false,
      "condition": false
    },
    advanced: {
      callbacks: {
        onNodeAdd: function onNodeAdd(dragment, currentNode) {
          var dragComponentName = dragment.componentName;
          if (isFormItemChild(dragComponentName)) {
            // 为目标元素包裹一层P
            var layoutPNode = currentNode.document.createNode({
              componentName: 'Form.Item',
              props: {
                label: 'formItem: '
              },
              children: [dragment.exportSchema()]
            });
            // 当前dragment还未添加入node子节点,需要setTimeout处理
            setTimeout(function () {
              currentNode.replaceChild(dragment, layoutPNode.exportSchema(),
              // 避免生成新的 nodeId
              {
                reserveSchemaNodeId: true
              });
            }, 1);
          }
        },
        onNodeRemove: function onNodeRemove(removedNode, currentNode) {
          if (!removedNode || !currentNode) {
            return;
          }
          var children = currentNode.children;
          // 若无children,则说明当前P组件内已为空,需要删除 FormItem 组件本身
          if (children && children.length === 0) {
            currentNode.remove();
          }
        }
      }
    }
  }
};