import React from 'react'
import type { Connection } from '@xyflow/react'

export type ConnectionFrom = { nodeId: string; sourceHandle?: string } | null

export type FlowContextValue = {
    nodes: any[]
    setNodes: (updater: any) => void
    edges: any[]
    setEdges: (updater: any) => void
    renamingNodeId: string | null
    setRenamingNodeId: (id: string | null) => void
    /** Set when user starts dragging from an output handle; cleared on connect end. Used to highlight valid targets. */
    connectionFrom: ConnectionFrom
    setConnectionFrom: (v: ConnectionFrom) => void
    isValidConnection: (connection: Connection) => boolean
}

const FlowContext = React.createContext<FlowContextValue | null>(null)

export default FlowContext
