import React, { useMemo } from 'react'; import { motion } from 'framer-motion'; import { COMPONENTS } from '../../data/components'; interface AnimatedMessageProps { from: string; to: string; label: string; color: string; delay: number; duration: number; speed: number; containerWidth: number; containerHeight: number; } export const AnimatedMessage: React.FC = React.memo( ({ from, to, label, color, delay, duration, speed, containerWidth, containerHeight }) => { const coords = useMemo(() => { const fromComp = COMPONENTS.find((c) => c.id === from); const toComp = COMPONENTS.find((c) => c.id === to); if (!fromComp || !toComp) return null; const x1 = (fromComp.position.x / 100) * containerWidth; const y1 = (fromComp.position.y / 100) * containerHeight; const x2 = (toComp.position.x / 100) * containerWidth; const y2 = (toComp.position.y / 100) * containerHeight; const midX = (x1 + x2) / 2; const dx = Math.abs(x2 - x1); const dy = Math.abs(y2 - y1); const curveFactor = Math.min(dx, dy) * 0.25; const midY = (y1 + y2) / 2 - curveFactor; return { x1, y1, x2, y2, midX, midY }; }, [from, to, containerWidth, containerHeight]); if (!coords) return null; const { x1, y1, x2, y2, midX, midY } = coords; const animDelay = delay / speed / 1000; const animDuration = duration / speed / 1000; const pathD = `M ${x1} ${y1} Q ${midX} ${midY} ${x2} ${y2}`; return ( <> {/* Trail line */} {/* Floating message bubble */} {label} ); } );