| 1 | 'use client'; |
| 2 | |
| 3 | import { useState } from 'react'; |
| 4 | import { motion, AnimatePresence } from 'framer-motion'; |
| 5 | import { Target, ChevronDown, ChevronUp, AlertTriangle, Ship, Anchor, AlertCircle, Maximize2, Minimize2 } from 'lucide-react'; |
| 6 | |
| 7 | interface ScmPanelProps { |
| 8 | data: any; |
| 9 | } |
| 10 | |
| 11 | export default function ScmPanel({ data }: ScmPanelProps) { |
| 12 | const [expanded, setExpanded] = useState(true); |
| 13 | const [maximized, setMaximized] = useState(false); |
| 14 | |
| 15 | const suppliers = data.scm_suppliers || []; |
| 16 | const criticalSuppliers = suppliers.filter((s: any) => s.risk_level === 'CRITICAL' || s.risk_level === 'HIGH'); |
| 17 | |
| 18 | const ports = data.maritime_ports || []; |
| 19 | const congestedPorts = ports.filter((p: any) => p.congestion === 'SEVERE' || p.congestion === 'CONGESTED'); |
| 20 | |
| 21 | const chokepoints = data.maritime_chokepoints || []; |
| 22 | const riskyChokes = chokepoints.filter((c: any) => c.risk === 'CRITICAL' || c.risk === 'HIGH'); |
| 23 | |
| 24 | const marketAlerts = data.markets?.scm_alerts || []; |
| 25 | |
| 26 | const totalRisks = criticalSuppliers.length + congestedPorts.length + riskyChokes.length + marketAlerts.length; |
| 27 | |
| 28 | return ( |
| 29 | <motion.div initial={{ opacity: 0, x: -20 }} animate={{ opacity: 1, x: 0 }} transition={{ delay: 0.7, duration: 0.6 }} className="glass-panel p-3 pointer-events-auto mt-3 border border-[#00BCD4]/30" style={{ background: 'rgba(0, 188, 212, 0.05)' }}> |
| 30 | <button onClick={() => setExpanded(!expanded)} className="flex items-center justify-between w-full mb-2"> |
| 31 | <div className="flex items-center gap-2"> |
| 32 | <Target className="w-3.5 h-3.5 text-[#00BCD4]" /> |
| 33 | <span className="hud-text text-[12px] text-[var(--text-primary)]">SCM RISK COMMAND</span> |
| 34 | {totalRisks > 0 && ( |
| 35 | <span className="gotham-tag gotham-tag--critical" style={{ fontSize: '7px', padding: '1px 4px' }}>{totalRisks} ALERTS</span> |
| 36 | )} |
| 37 | </div> |
| 38 | <div className="flex items-center gap-2"> |
| 39 | {expanded ? <ChevronUp className="w-3 h-3 text-[var(--text-muted)]" /> : <ChevronDown className="w-3 h-3 text-[var(--text-muted)]" />} |
| 40 | </div> |
| 41 | </button> |
| 42 | |
| 43 | <AnimatePresence> |
| 44 | {expanded && ( |
| 45 | <motion.div initial={{ height: 0, opacity: 0 }} animate={{ height: 'auto', opacity: 1 }} exit={{ height: 0, opacity: 0 }} transition={{ duration: 0.2 }} className="overflow-hidden flex flex-col flex-1 min-h-0"> |
| 46 | <div className="space-y-3 mt-2 overflow-y-auto styled-scrollbar pr-1 flex-1 pb-4"> |
| 47 | |
| 48 | {/* Market Alerts */} |
| 49 | {marketAlerts.length > 0 && ( |
| 50 | <div> |
| 51 | <div className="flex items-center gap-1.5 mb-1.5"> |
| 52 | <AlertCircle className="w-3 h-3 text-[#FF9500]" /> |
| 53 | <span className="text-[9px] font-mono text-[#FF9500] tracking-widest font-bold">MARKET IMPACT ALERTS</span> |
| 54 | </div> |
| 55 | <div className="space-y-1"> |
| 56 | {marketAlerts.map((alert: string, i: number) => ( |
| 57 | <div key={i} className="px-2 py-1.5 rounded border border-[#FF9500] bg-[#FF9500]/10 text-[#FF9500] text-[9px] font-mono leading-tight shadow-[0_0_8px_rgba(255,149,0,0.15)]"> |
| 58 | {alert} |
| 59 | </div> |
| 60 | ))} |
| 61 | </div> |
| 62 | </div> |
| 63 | )} |
| 64 | |
| 65 | {/* Suppliers */} |
| 66 | <div> |
| 67 | <div className="flex items-center gap-1.5 mb-1.5"> |
| 68 | <AlertTriangle className="w-3 h-3 text-[#FF1744]" /> |
| 69 | <span className="text-[9px] font-mono text-[var(--text-muted)] tracking-widest">CRITICAL SUPPLIERS</span> |
| 70 | </div> |
| 71 | {criticalSuppliers.length === 0 ? ( |
| 72 | <div className="text-[9px] font-mono text-[#00E676] px-2">✓ All monitored Tier 1/2 nodes operational.</div> |
| 73 | ) : ( |
| 74 | <div className="space-y-1"> |
| 75 | {criticalSuppliers.map((s: any, i: number) => { |
| 76 | const threats = s.active_threats ? JSON.parse(s.active_threats) : []; |
| 77 | return ( |
| 78 | <div key={i} className="px-2 py-1.5 rounded border border-[#FF1744]/40 bg-[#FF1744]/10"> |
| 79 | <div className="flex justify-between items-start mb-1"> |
| 80 | <span className="text-[10px] font-mono font-bold text-[#FF1744]">{s.name}</span> |
| 81 | <span className="text-[8px] font-mono text-[#FF1744]/80">{s.city}</span> |
| 82 | </div> |
| 83 | <div className="text-[8px] font-mono text-[#E8E6E0]">{threats.join(' • ')}</div> |
| 84 | </div> |
| 85 | ); |
| 86 | })} |
| 87 | </div> |
| 88 | )} |
| 89 | </div> |
| 90 | |
| 91 | {/* Ports & Chokepoints */} |
| 92 | <div> |
| 93 | <div className="flex items-center gap-1.5 mb-1.5"> |
| 94 | <Anchor className="w-3 h-3 text-[#FF9500]" /> |
| 95 | <span className="text-[9px] font-mono text-[var(--text-muted)] tracking-widest">CONGESTED NODES</span> |
| 96 | </div> |
| 97 | {(congestedPorts.length === 0 && riskyChokes.length === 0) ? ( |
| 98 | <div className="text-[9px] font-mono text-[#00E676] px-2">✓ Global maritime flow optimal.</div> |
| 99 | ) : ( |
| 100 | <div className="space-y-1"> |
| 101 | {riskyChokes.map((c: any, i: number) => ( |
| 102 | <div key={`c-${i}`} className="px-2 py-1.5 rounded hover:bg-white/5 transition-colors border-l-2" style={{ borderLeftColor: c.risk === 'CRITICAL' ? '#FF1744' : '#FF9500' }}> |
| 103 | <div className="flex justify-between items-center mb-0.5"> |
| 104 | <span className="text-[10px] font-mono text-[#FF9500] font-bold">{c.name}</span> |
| 105 | <span className="text-[8px] font-mono font-bold px-1 rounded" style={{ background: c.risk === 'CRITICAL' ? '#FF1744' : '#FF9500', color: '#000' }}>{c.risk}</span> |
| 106 | </div> |
| 107 | <div className="text-[8px] font-mono text-[#aaa]">{c.traffic}</div> |
| 108 | </div> |
| 109 | ))} |
| 110 | {congestedPorts.map((p: any, i: number) => ( |
| 111 | <div key={`p-${i}`} className="px-2 py-1.5 rounded hover:bg-white/5 transition-colors border-l-2" style={{ borderLeftColor: p.congestion === 'SEVERE' ? '#FF1744' : '#FF9500' }}> |
| 112 | <div className="flex justify-between items-center mb-0.5"> |
| 113 | <span className="text-[10px] font-mono text-[#00BCD4]">{p.name}</span> |
| 114 | <span className="text-[8px] font-mono font-bold px-1 rounded" style={{ background: p.congestion === 'SEVERE' ? '#FF1744' : '#FF9500', color: '#000' }}>{p.congestion}</span> |
| 115 | </div> |
| 116 | <div className="flex justify-between items-center text-[8px] font-mono text-[#aaa]"> |
| 117 | <span>DWELL: <span className="text-[#fff]">{p.dwell_time}</span></span> |
| 118 | <span>{p.volume.split(' | ')[1]}</span> |
| 119 | </div> |
| 120 | </div> |
| 121 | ))} |
| 122 | </div> |
| 123 | )} |
| 124 | </div> |
| 125 | |
| 126 | </div> |
| 127 | </motion.div> |
| 128 | )} |
| 129 | </AnimatePresence> |
| 130 | </motion.div> |
| 131 | ); |
| 132 | } |