import React from 'react';
import { Node } from '@xyflow/react';
import BasicNodeEditor from './BasicNodeEditor';
import StartNodeEditor from './StartNodeEditor';
import EndNodeEditor from './EndNodeEditor';
import LocalNodeEditor from './LocalNodeEditor';

// 定义节点编辑器的属性接口
export interface NodeEditorProps {
  node?: Node;
  nodeData: any;
  updateNodeData: (key: string, value: any) => void;
}

// 节点编辑器映射
export const nodeEditors: Record<string, React.FC<NodeEditorProps>> = {
  'basic': BasicNodeEditor,
  'start': StartNodeEditor,
  'end': EndNodeEditor,
  'local': LocalNodeEditor  // 用于所有本地节点类型的编辑器
};

// 注册新的节点编辑器
export const registerNodeEditor = (
  type: string,
  component: React.FC<NodeEditorProps>
) => {
  nodeEditors[type] = component;
};

// 根据节点类型获取对应的编辑器
export const getNodeEditorByType = (nodeType: string, localNodeType?: string) => {
  // 对于本地节点，使用专门的本地节点编辑器
  if (localNodeType) {
    return nodeEditors['local'] || nodeEditors['basic'];
  }

  // 对于预定义节点类型，直接返回对应编辑器
  return nodeEditors[nodeType] || nodeEditors['basic'];
};

export default {
  nodeEditors,
  registerNodeEditor,
  getNodeEditorByType
};