import { BaseEdge, EdgeLabelRenderer, getBezierPath, type EdgeProps, } from "@xyflow/react"; import type { EdgeData } from "@/stores/graphStore"; function conditionLabel(condition: string): string { if (condition.startsWith("contains:")) return `kw: ${condition.slice(9)}`; return condition; } export function ConditionalEdge({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, style = {}, markerEnd, data, }: EdgeProps) { const edgeData = data as unknown as EdgeData | undefined; const [edgePath, labelX, labelY] = getBezierPath({ sourceX, sourceY, sourcePosition, targetX, targetY, targetPosition, }); const condition = edgeData?.condition; const evaluated = edgeData?.evaluated; const weight = edgeData?.weight ?? 1.0; // Dim low-weight edges const opacity = weight < 0.3 ? 0.4 : weight < 0.6 ? 0.7 : 1; const strokeColor = evaluated === true ? "#22c55e" : evaluated === false ? "#94a3b8" : "#6366f1"; const hasLabel = condition || weight < 1.0; return ( <> {hasLabel && ( {condition && ( {conditionLabel(condition)} )} {weight < 1.0 && ( {condition ? " " : ""}w:{weight.toFixed(2)} )} )} > ); }