import { useStandardQuery } from '@szl-holdings/api-client-react'; import { color } from '@szl-holdings/design-system'; import { apiFetch } from '@szl-holdings/shared-ui/api-fetch'; import { cn } from '@szl-holdings/shared-ui/utils'; import { Anchor, ArrowRight, BarChart3, Box, Clock, DollarSign, Download, Droplets, Filter, Fuel, Layers, MapPin, Navigation, Package, Ship, TrendingDown, TrendingUp, Wheat, Wifi, WifiOff, } from 'lucide-react'; import { useState } from 'react'; import { Bar, BarChart, CartesianGrid, ResponsiveContainer, Tooltip, XAxis, YAxis, } from 'recharts'; const COMMODITIES = [ { id: 'crude', name: 'Crude Oil', icon: Droplets, color: '#f97316', unit: 'MB/day', volume: 82.4, change: +2.1, vessels: 142, avg_days: 21, }, { id: 'lng', name: 'LNG', icon: Fuel, color: '#38bdf8', unit: 'MT/month', volume: 34.1, change: -1.4, vessels: 67, avg_days: 18, }, { id: 'bulk', name: 'Dry Bulk', icon: Wheat, color: '#f59e0b', unit: 'MT/week', volume: 128.7, change: +5.3, vessels: 234, avg_days: 14, }, { id: 'container', name: 'Containers', icon: Box, color: '#a855f7', unit: 'TEU/week', volume: 2840, change: +1.7, vessels: 89, avg_days: 25, }, ]; const PORT_CONGESTION = [ { port: 'Singapore', country: 'SGP', lat: 1.3, lon: 103.8, vessels_waiting: 47, avg_wait_hrs: 31, capacity_pct: 94, risk: 'high', commodity: 'Crude + Container', }, { port: 'Rotterdam', country: 'NLD', lat: 51.9, lon: 4.5, vessels_waiting: 23, avg_wait_hrs: 14, capacity_pct: 78, risk: 'medium', commodity: 'Container + Bulk', }, { port: 'Fujairah', country: 'UAE', lat: 25.1, lon: 56.3, vessels_waiting: 38, avg_wait_hrs: 22, capacity_pct: 89, risk: 'high', commodity: 'Crude + Bunker', }, { port: 'Houston', country: 'USA', lat: 29.7, lon: -95.0, vessels_waiting: 15, avg_wait_hrs: 9, capacity_pct: 62, risk: 'low', commodity: 'LNG + Crude', }, { port: 'Qingdao', country: 'CHN', lat: 36.1, lon: 120.4, vessels_waiting: 31, avg_wait_hrs: 18, capacity_pct: 83, risk: 'medium', commodity: 'Iron Ore + Coal', }, { port: 'Algeciras', country: 'ESP', lat: 36.1, lon: -5.4, vessels_waiting: 12, avg_wait_hrs: 6, capacity_pct: 55, risk: 'low', commodity: 'Container Transit', }, { port: 'Corpus Christi', country: 'USA', lat: 27.8, lon: -97.4, vessels_waiting: 8, avg_wait_hrs: 4, capacity_pct: 48, risk: 'low', commodity: 'LNG Export', }, ]; const FLOW_ROUTES = [ { id: 'persian-asia', name: 'Persian Gulf → Asia', from: 'Fujairah / Kharg', to: 'Singapore / Qingdao', commodity: 'Crude Oil', volume: '18.4 MB/day', vessels_active: 89, risk: 'medium', canal: 'Strait of Hormuz', choke_risk: true, }, { id: 'us-europe', name: 'US Gulf → NW Europe', from: 'Houston / Corpus Christi', to: 'Rotterdam / Wilhelmshaven', commodity: 'LNG + Crude', volume: '4.2 MT/month', vessels_active: 34, risk: 'low', canal: 'Direct Atlantic', choke_risk: false, }, { id: 'australia-china', name: 'Australia → China', from: 'Port Hedland / Newcastle', to: 'Qingdao / Tianjin', commodity: 'Iron Ore + Coal', volume: '64.2 MT/month', vessels_active: 67, risk: 'low', canal: 'South China Sea', choke_risk: false, }, { id: 'red-sea', name: 'Red Sea Transit', from: 'Suez Canal', to: 'All Directions', commodity: 'Mixed', volume: '12% of global trade', vessels_active: 41, risk: 'critical', canal: 'Bab el-Mandeb / Suez', choke_risk: true, }, { id: 'russia-asia', name: 'Russia → Asia (Northern Route)', from: 'Novorossiysk / Primorsk', to: 'India / China', commodity: 'Sanctioned Crude', volume: 'Est. 2.1 MB/day', vessels_active: 28, risk: 'critical', canal: 'Around Cape', choke_risk: false, }, ]; const VOYAGE_COST = [ { month: 'Sep', voyage_cost: 42, bunker: 28, port: 8, canal: 6 }, { month: 'Oct', voyage_cost: 45, bunker: 30, port: 9, canal: 6 }, { month: 'Nov', voyage_cost: 48, bunker: 32, port: 10, canal: 6 }, { month: 'Dec', voyage_cost: 52, bunker: 35, port: 10, canal: 7 }, { month: 'Jan', voyage_cost: 51, bunker: 34, port: 10, canal: 7 }, { month: 'Feb', voyage_cost: 54, bunker: 36, port: 11, canal: 7 }, { month: 'Mar', voyage_cost: 57, bunker: 38, port: 12, canal: 7 }, ]; const RATE_DATA = [ { route: 'VLCC AG/China (TD3C)', current: 42.8, prev: 38.1, unit: 'WS', trend: 'up' }, { route: 'Suezmax W.Africa/UKC (TD20)', current: 87.2, prev: 92.4, unit: 'WS', trend: 'down' }, { route: 'Aframax NS/UKC (TD7)', current: 118.5, prev: 108.0, unit: 'WS', trend: 'up' }, { route: 'LNG Pacific (BLNG3G)', current: 62400, prev: 68200, unit: '$/day', trend: 'down' }, { route: 'Capesize C5 (FE/China)', current: 14.2, prev: 12.8, unit: '$/MT', trend: 'up' }, ]; const VESSEL_QUEUE = [ { vessel: 'NORDIC CROWN', imo: '9847234', type: 'VLCC', port: 'Fujairah', wait_hrs: 42, cargo: '1.95 MB Crude', eta_berth: '2026-04-03', }, { vessel: 'PACIFIC EMPRESS', imo: '9521087', type: 'VLCC', port: 'Singapore', wait_hrs: 28, cargo: '2.0 MB Crude', eta_berth: '2026-04-02', }, { vessel: 'MSC AMSTERDAM', imo: '9768341', type: 'ULCS', port: 'Singapore', wait_hrs: 19, cargo: '18,420 TEU', eta_berth: '2026-04-02', }, { vessel: 'EXCEL GALAXY', imo: '9412567', type: 'Capesize', port: 'Qingdao', wait_hrs: 22, cargo: '160k MT Iron Ore', eta_berth: '2026-04-02', }, { vessel: 'ATLANTIC GAS', imo: '9634112', type: 'LNG Carrier', port: 'Rotterdam', wait_hrs: 11, cargo: '138k CBM LNG', eta_berth: '2026-04-01', }, ]; const riskColors: Record = { critical: color.accent.red, high: color.accent.amber, medium: color.accent.amber, low: color.accent.green, }; interface ChokepointAlert { id: string; name: string; status: string; risk: string; affectedVessels?: number; region?: string; } interface ChokepointsResponse { data: { chokepoints?: ChokepointAlert[]; fetchedAt?: string }; } interface FleetSummaryResponse { data: { totalVessels?: number; activeVessels?: number; inPort?: number; atAnchor?: number; criticalAlerts?: number; fetchedAt?: string; }; } export default function CommodityFlowIntelligence() { const [selectedCommodity, setSelectedCommodity] = useState('crude'); const [activeRoute, setActiveRoute] = useState('red-sea'); const BG = '#060e1a'; const SURFACE = '#081018'; const BORDER = 'rgba(77,143,204,0.1)'; const _SKY = 'var(--gi-accent-blue)'; const { data: chokepointsData, isError: isChokepointsError } = useStandardQuery({ queryKey: ['commodity-flow-chokepoints'], queryFn: () => apiFetch('/vessels/live/chokepoints'), refetchInterval: 30000, retry: 1, }); const { data: fleetSummaryData } = useStandardQuery({ queryKey: ['commodity-flow-fleet-summary'], queryFn: () => apiFetch('/vessels/live/fleet-summary'), refetchInterval: 30000, retry: 1, }); const liveChokepoints = chokepointsData?.data?.chokepoints ?? []; const liveFleet = fleetSummaryData?.data; const isLive = !isChokepointsError && liveChokepoints.length > 0; return (
{/* Header */}

Commodity Flow Intelligence

Global cargo flows · Port analytics · Rate intelligence

{isLive ? ( ) : ( )} {isLive ? `LIVE · ${liveChokepoints.length} chokepoints monitored` : 'LIVE · AIS + Port Data'}
{liveFleet && ( <>
{liveFleet.totalVessels ?? '—'} vessels tracked {(liveFleet.criticalAlerts ?? 0) > 0 && ( {liveFleet.criticalAlerts} critical alerts )}
)}
{/* Commodity selector KPIs */}
{COMMODITIES.map((c) => { const Icon = c.icon; const isSelected = selectedCommodity === c.id; return ( ); })}
{/* Main 3-column grid */}
{/* Port congestion */}
Port Congestion Index
Live · 7 major ports
{[...PORT_CONGESTION] .sort((a, b) => b.vessels_waiting - a.vessels_waiting) .map((port) => (
{port.port} {port.country}
{port.vessels_waiting} vessels
Avg wait:{' '} {port.avg_wait_hrs}h {port.commodity}
{port.capacity_pct}%
))}
{/* Trade routes */}
Major Trade Corridors · Risk Assessment
{FLOW_ROUTES.map((route) => ( ))}
{/* Freight rate table */}
Spot Freight Rates · Baltic Exchange
{RATE_DATA.map((r) => (
{r.route}
{r.prev} {r.unit}
{typeof r.current === 'number' && r.current > 999 ? r.current.toLocaleString() : r.current}{' '} {r.unit} {r.trend === 'up' ? ( ) : ( )}
))}
{/* Voyage cost chart + vessel queue */}
Average Voyage Cost Breakdown (USD/MT)
{[ ['Bunker', '#f97316'], ['Port', 'var(--gi-accent-blue)'], ['Canal', '#a855f7'], ].map(([label, color]) => (
{label}
))}
Anchorage Queue — Waiting Vessels
{VESSEL_QUEUE.length} vessels monitoring
{VESSEL_QUEUE.map((v) => (
{v.vessel} = 30 ? '#f97316' : v.wait_hrs >= 20 ? '#f59e0b' : '#22c55e', }} > {v.wait_hrs}h wait
IMO {v.imo} · {v.type} · {v.port}
{v.cargo} · Berth ETA: {v.eta_berth}
))}
); }