import { registerNode } from './registerNode';

export default async function formSchemaService(args: any) {
  const { targetType, targetData } = args;
  const isGroup = targetData?.isGroup;
  const groupSchema = {
    tabs: [
      {
        name: '设置',
        groups: [
          {
            name: 'groupName',
            controls: [
              {
                label: '分组名',
                name: 'group-service',
                shape: 'group-service',
                placeholder: '分组名称',
              },
            ],
          },
        ],
      },
    ],
  };

  const edgeSchema = {
    tabs: [
      {
        name: '设置',
        groups: [
          {
            name: 'groupName',
            controls: [
              {
                label: '边',
                name: 'edge-service',
                shape: 'edge-service',
                placeholder: '边名称',
              },
            ],
          },
        ],
      },
    ],
  };

  if (isGroup) {
    return groupSchema;
  }
  if (targetType === 'edge') {
    return edgeSchema;
  }
  if (targetType === 'node') {
    // console.log(targetData);

    return getNodeSchema(targetData.name);
  }
  return {
    tabs: [
      {
        name: '设置',
        groups: [
          {
            name: 'groupName',
            controls: [
              {
                label: '',
                name: 'canvas-service',
                shape: 'canvas-service',
              },
            ],
          },
        ],
      },
    ],
  };
}

const getNodeSchema: any = (shapeName: String) => {
  // 判断是否为自定义节点
  let node = registerNode.find((node) => node.name == shapeName);
  let name = node?.name || 'node-service';
  return {
    tabs: [
      {
        name: '设置',
        groups: [
          {
            name: 'groupName',
            controls: [
              {
                label: '节点名',
                name: name,
                shape: name,
                placeholder: '节点名称',
              },
            ],
          },
        ],
      },
    ],
  };
};
