import { Edge, NodeProps, Node, OnConnect, OnEdgesChange, OnNodesChange, Connection, NodeChange, EdgeChange, OnSelectionChangeParams, XYPosition } from "@xyflow/react";
import { GraphEdge } from "./edges/GraphEdge";
import { GraphNode } from "./nodes/GraphNode";
import { ControlPoint } from "./layout/edge/point";
import { ReactFlowLayout, ReactFlowLayoutConfig } from "./layout/node";
// 添加新的类型定义
export type HistoryState = {
    nodes: Node[];
    edges: Edge[];
    type: string; // 记录操作类型
    timestamp: number;
};

export type GraphState = {
    past: Array<{ nodes: Node[], edges: Edge[] }>;
    present: {
        nodes: Node[];
        edges: Edge[];
    };
    future: Array<{ nodes: Node[], edges: Edge[] }>;
    canUndo: () => boolean;
    canRedo: () => boolean;
    onNodesChange: (changes: NodeChange[]) => void;
    onEdgesChange: (changes: EdgeChange[]) => void;
    updateNode: (id: string, data: any) => void;
    undo: () => void;
    redo: () => void;
    setNodes: (nodes: Node[]) => void;
    setEdges: (edges: Edge[]) => void;
    record: (callback: () => void) => void
};
export const nodeTypes = {
    'graph-node': GraphNode
}

export const edgeTypes = {
    'graph-edge': GraphEdge
}

export interface ReactFlowGraph {
    nodes: Node[]
    edges: Edge[]
}
export interface ReactFlowEdgePort {
    /**
     * Total number of edges in this direction (source or target).
     */
    edges: number;
    /**
     * Number of ports
     */
    portCount: number;
    /**
     * Port's index.
     */
    portIndex: number;
    /**
     * Total number of Edges under the current port.
     */
    edgeCount: number;
    /**
     * Index of the Edge under the current port.
     */
    edgeIndex: number;
}

export interface EdgeLayout {
    /**
     * SVG path for edge rendering
     */
    path: string;
    /**
     * Control points on the edge.
     */
    points: ControlPoint[];
    labelPosition: XYPosition;
    /**
     * Current layout dependent variables (re-layout when changed).
     */
    deps?: any;
    /**
     * Potential control points on the edge, for debugging purposes only.
     */
    inputPoints: ControlPoint[];
}

export interface ReactFlowEdgeData {
    /**
     * Data related to the current edge's layout, such as control points.
     */
    layout?: EdgeLayout;
    sourcePort: ReactFlowEdgePort;
    targetPort: ReactFlowEdgePort;
}
