import React from 'react';
import { NodeTypes } from '@xyflow/react';
import StartNode from './startNode/StartNode';
import EndNode from './endNode/EndNode';
import BasicNode from './basicNode/BasicNode';

// 定义所有可用的节点类型
export const nodeTypes: NodeTypes = {
  start: StartNode,
  end: EndNode,
  BASIC: BasicNode
};

// 节点类型映射，用于创建节点时的类型查找
export const nodeTypeMap: Record<string, string> = {
  'start': 'start',
  'end': 'end',
  'basic': 'BASIC'
};

// 节点显示名称映射
export const nodeTypeNameMap: Record<string, string> = {
  'start': '开始节点',
  'end': '结束节点',
  'basic': '基础节点'
};

// 注册新节点类型的函数
export const registerNodeType = (
  type: string,
  component: React.ComponentType<any>,
  displayName?: string
) => {
  // 在nodeTypes中注册节点组件
  (nodeTypes as any)[type] = component;

  // 在nodeTypeMap中添加类型映射
  nodeTypeMap[type] = type;

  // 在nodeTypeNameMap中添加显示名称
  nodeTypeNameMap[type] = displayName || type;
};

export default {
  nodeTypes,
  nodeTypeMap,
  nodeTypeNameMap,
  registerNodeType
};