import React, { useMemo, useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import type { SystemComponent as SystemComponentType } from '../../data/types'; import { Icon } from '../shared/Icon'; import { COMPONENT_ICONS, COMPONENT_ROLES } from '../../utils/iconMap'; interface SystemComponentProps { component: SystemComponentType; isActive: boolean; isReceiving: boolean; onClick?: () => void; } export const SystemComponent: React.FC = React.memo( ({ component, isActive, isReceiving, onClick }) => { const [hovered, setHovered] = useState(false); const iconName = COMPONENT_ICONS[component.id] || 'circle'; const role = COMPONENT_ROLES[component.id] || 'Service'; const glowStyle = useMemo(() => { if (isReceiving) { return { boxShadow: `0 0 30px ${component.color}40, 0 0 60px ${component.color}20`, borderColor: `${component.color}80`, }; } if (isActive) { return { boxShadow: `0 0 20px ${component.color}30, 0 0 40px ${component.color}15`, borderColor: `${component.color}50`, }; } return { boxShadow: '0 4px 20px rgba(0,0,0,0.2)', borderColor: 'rgba(255,255,255,0.05)', }; }, [isActive, isReceiving, component.color]); return ( <> setHovered(true)} onMouseLeave={() => setHovered(false)} className="absolute z-10 flex cursor-pointer flex-col items-center gap-2 rounded-2xl p-4 transition-colors glass-panel group" style={{ left: `${component.position.x}%`, top: `${component.position.y}%`, transform: 'translate(-50%, -50%)', background: isActive ? `linear-gradient(135deg, ${component.color}12, ${component.color}06)` : 'rgba(47, 41, 56, 0.4)', backdropFilter: 'blur(12px)', ...glowStyle, minWidth: '116px', minHeight: '120px', }} animate={ isReceiving ? { scale: [1, 1.05, 1] } : { scale: 1 } } transition={ isReceiving ? { duration: 0.6, ease: 'easeInOut' } : { duration: 0.3 } } whileHover={{ scale: 1.05 }} aria-label={`${component.label}: ${component.description}`} tabIndex={0} > {/* Role tag */}
{role}
{/* Icon with gradient background */}
{/* Label */}

{component.label}

{/* Status */}
{isReceiving ? 'Processing' : isActive ? 'Online' : 'Idle'}
{/* Connection points */}
{/* Tooltip */} {hovered && (
{component.label}
{component.description}
)}
); } );