"use client" import { useEffect, useRef, useState } from "react" import type { JSX } from "react/jsx-runtime" // Import JSX to fix the undeclared variable error interface FlowVisualProps { allocations: { id: string; amount: number; color: string }[] containerHeight: number } export function FlowVisual({ allocations, containerHeight }: FlowVisualProps) { const [paths, setPaths] = useState([]) const containerRef = useRef(null) // Calculate paths whenever allocations change or window resizes useEffect(() => { const updatePaths = () => { if (!containerRef.current) return const containerWidth = containerRef.current.clientWidth const sourceX = containerWidth / 2 const sourceY = 0 // Top center const newPaths = allocations.map((alloc, index) => { // Calculate target position based on index and total items // We assume the target cards are distributed evenly at the bottom // This is a visual approximation to match the grid layout const totalItems = allocations.length const sectionWidth = containerWidth / totalItems const targetX = sectionWidth * index + sectionWidth / 2 const targetY = containerHeight - 20 // Bottom, slightly offset // Bezier curve control points const cp1x = sourceX const cp1y = containerHeight * 0.5 const cp2x = targetX const cp2y = containerHeight * 0.5 // Stroke width based on allocation amount (normalized) const maxAllocation = Math.max(...allocations.map((a) => a.amount)) const strokeWidth = Math.max(2, (alloc.amount / maxAllocation) * 20) return ( {/* Glow Effect Path */} {/* Main Flow Path */} {/* Moving Particle */} ) }) setPaths(newPaths) } updatePaths() window.addEventListener("resize", updatePaths) return () => window.removeEventListener("resize", updatePaths) }, [allocations, containerHeight]) return (
{paths}
) }