'use client' import { useCallback } from 'react' import { getSmoothStepPath, EdgeLabelRenderer, BaseEdge, type EdgeProps, } from '@xyflow/react' import type { AllocationEdgeData } from '@/lib/types' export default function AllocationEdge({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data, style, markerEnd, }: EdgeProps) { const edgeData = data as AllocationEdgeData | undefined const [edgePath, labelX, labelY] = getSmoothStepPath({ sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, }) const allocation = edgeData?.allocation ?? 0 const color = edgeData?.color ?? '#94a3b8' const hasSiblings = (edgeData?.siblingCount ?? 1) > 1 const handleAdjust = useCallback( (delta: number) => { if (!edgeData?.onAdjust || !edgeData.sourceId || !edgeData.targetId || !edgeData.edgeType) return edgeData.onAdjust(edgeData.sourceId, edgeData.targetId, edgeData.edgeType, delta) }, [edgeData] ) return ( <>
{hasSiblings && ( )} {Math.round(allocation)}% {hasSiblings && ( )}
) }