| 1 | 'use client'; |
| 2 | |
| 3 | import { useState } from 'react'; |
| 4 | import { motion, AnimatePresence } from 'framer-motion'; |
| 5 | import { |
| 6 | ChevronDown, ChevronUp, MapPin, ExternalLink, AlertTriangle, |
| 7 | Newspaper, Clock, Radio, Maximize2, Minimize2 |
| 8 | } from 'lucide-react'; |
| 9 | |
| 10 | interface LiveAlertsProps { |
| 11 | data: any; |
| 12 | onLocate: (lat: number, lng: number) => void; |
| 13 | onWatchFeed?: (url: string, name: string) => void; |
| 14 | } |
| 15 | |
| 16 | const RISK_COLORS: Record<string, string> = { |
| 17 | HIGH: '#FF3D3D', |
| 18 | CRITICAL: '#FF1744', |
| 19 | ELEVATED: '#FF9500', |
| 20 | MODERATE: '#FFD700', |
| 21 | LOW: '#00E676', |
| 22 | }; |
| 23 | |
| 24 | export default function LiveAlerts({ data, onLocate, onWatchFeed }: LiveAlertsProps) { |
| 25 | const [expanded, setExpanded] = useState(true); |
| 26 | const [maximized, setMaximized] = useState(false); |
| 27 | const [filter, setFilter] = useState<'all' | 'news' | 'quakes' | 'feeds'>('all'); |
| 28 | |
| 29 | // Built-in live feeds — verified video IDs (synced with /api/live-news) |
| 30 | const BUILTIN_FEEDS = [ |
| 31 | // ── North America ── |
| 32 | { name: 'NBC News NOW', city: 'New York', country: 'US', lat: 40.759, lng: -73.980, url: 'https://www.youtube.com/embed/live_stream?channel=UCeY0bbntWzzVIaj2z3QigXg&autoplay=1&mute=1', category: 'mainstream', region: 'americas' }, |
| 33 | { name: 'CBS News 24/7', city: 'New York', country: 'US', lat: 40.764, lng: -73.973, url: 'https://www.youtube.com/embed/live_stream?channel=UC8p1vwvWtl6T73JiExfWs1g&autoplay=1&mute=1', category: 'mainstream', region: 'americas' }, |
| 34 | { name: 'ABC News Live', city: 'New York', country: 'US', lat: 40.763, lng: -73.979, url: 'https://www.youtube.com/embed/live_stream?channel=UCBi2mrWuNuyYy4gbM6fU18Q&autoplay=1&mute=1', category: 'mainstream', region: 'americas' }, |
| 35 | { name: 'Bloomberg TV', city: 'New York', country: 'US', lat: 40.756, lng: -73.988, url: 'https://www.youtube.com/embed/live_stream?channel=UC_vQ72b7v5n2938v9d5c80w&autoplay=1&mute=1', category: 'finance', region: 'americas' }, |
| 36 | { name: 'C-SPAN', city: 'Washington DC', country: 'US', lat: 38.897, lng: -77.036, url: 'https://www.youtube.com/embed/live_stream?channel=UCb--64Gl51jIEVE-GLDAVTg&autoplay=1&mute=1', category: 'government', region: 'americas' }, |
| 37 | { name: 'CBC News', city: 'Toronto', country: 'CA', lat: 43.644, lng: -79.387, url: 'https://www.youtube.com/embed/live_stream?channel=UCKy1dAqELon0zgzZPOz9SVw&autoplay=1&mute=1', category: 'mainstream', region: 'americas' }, |
| 38 | // ── Europe ── |
| 39 | { name: 'Sky News', city: 'London', country: 'GB', lat: 51.500, lng: -0.118, url: 'https://www.youtube.com/embed/live_stream?channel=UCoMdktPbSTixAyNGwb-UYkQ&autoplay=1&mute=1', category: 'mainstream', region: 'europe' }, |
| 40 | { name: 'France 24 EN', city: 'Paris', country: 'FR', lat: 48.830, lng: 2.280, url: 'https://www.youtube.com/embed/live_stream?channel=UCQfwfsi5VrQ8yKZ-UWmAEFg&autoplay=1&mute=1', category: 'mainstream', region: 'europe' }, |
| 41 | { name: 'DW News', city: 'Berlin', country: 'DE', lat: 52.508, lng: 13.376, url: 'https://www.youtube.com/embed/live_stream?channel=UCknLrEdhRCp1aegoMqRaCZg&autoplay=1&mute=1', category: 'mainstream', region: 'europe' }, |
| 42 | { name: 'Euronews', city: 'Lyon', country: 'FR', lat: 45.764, lng: 4.836, url: 'https://www.youtube.com/embed/live_stream?channel=UCtUbOIRGKZkW7555n6x6q6g&autoplay=1&mute=1', category: 'mainstream', region: 'europe' }, |
| 43 | { name: 'TRT World', city: 'Istanbul', country: 'TR', lat: 41.008, lng: 28.978, url: 'https://www.youtube.com/embed/live_stream?channel=UC7fWeaHZQg1p9-4v98L1D1A&autoplay=1&mute=1', category: 'mainstream', region: 'europe' }, |
| 44 | { name: 'UKRINFORM', city: 'Kyiv', country: 'UA', lat: 50.450, lng: 30.523, url: 'https://www.youtube.com/embed/live_stream?channel=UCaDkCK6iFHPE0lmpaYL-WxQ&autoplay=1&mute=1', category: 'conflict', region: 'europe' }, |
| 45 | // ── Middle East ── |
| 46 | { name: 'Al Jazeera EN', city: 'Doha', country: 'QA', lat: 25.286, lng: 51.534, url: 'https://www.youtube.com/embed/live_stream?channel=UCNye-wNBqNL5ZzHSJj3l8Bg&autoplay=1&mute=1', category: 'mainstream', region: 'middleeast' }, |
| 47 | { name: 'Al Mayadeen', city: 'Beirut', country: 'LB', lat: 33.8886, lng: 35.4955, url: 'https://www.youtube.com/embed/live_stream?channel=UCZCFHCU-2eGF7V5ciMkoPHw&autoplay=1&mute=1', category: 'conflict', region: 'middleeast' }, |
| 48 | { name: 'LBCI Lebanon', city: 'Beirut', country: 'LB', lat: 33.8930, lng: 35.5018, url: 'https://www.youtube.com/embed/live_stream?channel=UCpE6gpKewomi17XDyPfpFjA&autoplay=1&mute=1', category: 'mainstream', region: 'middleeast' }, |
| 49 | // ── Asia Pacific ── |
| 50 | { name: 'NHK World', city: 'Tokyo', country: 'JP', lat: 35.690, lng: 139.692, url: 'https://www.youtube.com/embed/live_stream?channel=UCSPEjw8F2nQDtmUKPFNF7_A&autoplay=1&mute=1', category: 'mainstream', region: 'asia' }, |
| 51 | { name: 'CNA 24/7', city: 'Singapore', country: 'SG', lat: 1.290, lng: 103.852, url: 'https://www.youtube.com/embed/live_stream?channel=UC83jt4dlz1Gjl58fzQrrKZg&autoplay=1&mute=1', category: 'mainstream', region: 'asia' }, |
| 52 | { name: 'WION', city: 'New Delhi', country: 'IN', lat: 28.614, lng: 77.209, url: 'https://www.youtube.com/embed/live_stream?channel=UC_gUM8rL-Lrg6O3adPW9K1g&autoplay=1&mute=1', category: 'mainstream', region: 'asia' }, |
| 53 | { name: 'Arirang', city: 'Seoul', country: 'KR', lat: 37.566, lng: 126.978, url: 'https://www.youtube.com/embed/live_stream?channel=UCw9-5Y1CjW7Qy1Yf5q1y2-Q&autoplay=1&mute=1', category: 'mainstream', region: 'asia' }, |
| 54 | { name: 'ABC AU', city: 'Sydney', country: 'AU', lat: -33.868, lng: 151.209, url: 'https://www.youtube.com/embed/live_stream?channel=UC5iLnYoF4Ryb63YdGD9RfWQ&autoplay=1&mute=1', category: 'mainstream', region: 'asia' }, |
| 55 | // ── Africa ── |
| 56 | { name: 'Africanews', city: 'Pointe-Noire', country: 'CG', lat: -4.778, lng: 11.865, url: 'https://www.youtube.com/embed/live_stream?channel=UC5T2fB_W0Z31T0c8yN36a8A&autoplay=1&mute=1', category: 'mainstream', region: 'africa' }, |
| 57 | { name: 'SABC News', city: 'Johannesburg', country: 'ZA', lat: -26.204, lng: 28.047, url: 'https://www.youtube.com/embed/live_stream?channel=UC8yH-uI81UUtEMDsowQyx1g&autoplay=1&mute=1', category: 'mainstream', region: 'africa' }, |
| 58 | // ── Latin America ── |
| 59 | { name: 'teleSUR EN', city: 'Caracas', country: 'VE', lat: 10.491, lng: -66.902, url: 'https://www.youtube.com/embed/live_stream?channel=UCmuTmpLY35O3csvhyA6vrkg&autoplay=1&mute=1', category: 'mainstream', region: 'americas' }, |
| 60 | ]; |
| 61 | |
| 62 | // Build unified alert feed |
| 63 | const alerts: any[] = []; |
| 64 | |
| 65 | // OSINT Telegram News Feed (from /api/news) |
| 66 | if (data.news) { |
| 67 | data.news.forEach((a: any) => { |
| 68 | alerts.push({ |
| 69 | type: 'news', title: a.title, description: a.description, source: a.source, |
| 70 | lat: a.coords?.[0], lng: a.coords?.[1], time: a.published, |
| 71 | severity: (a.risk_score ?? 1) >= 8 ? 'CRITICAL' : (a.risk_score ?? 1) >= 6 ? 'HIGH' : (a.risk_score ?? 1) >= 4 ? 'ELEVATED' : 'LOW', |
| 72 | url: a.link, |
| 73 | }); |
| 74 | }); |
| 75 | } |
| 76 | |
| 77 | // Earthquakes |
| 78 | if (data.earthquakes) { |
| 79 | data.earthquakes.slice(0, 5).forEach((eq: any) => { |
| 80 | alerts.push({ |
| 81 | type: 'quake', title: `M${eq.magnitude} - ${eq.place}`, source: 'USGS', |
| 82 | lat: eq.lat, lng: eq.lng, time: eq.time, |
| 83 | severity: eq.magnitude >= 6 ? 'CRITICAL' : eq.magnitude >= 4.5 ? 'HIGH' : 'MODERATE', |
| 84 | }); |
| 85 | }); |
| 86 | } |
| 87 | |
| 88 | // Built-in live feeds (always present) |
| 89 | BUILTIN_FEEDS.forEach(f => { |
| 90 | alerts.push({ |
| 91 | type: 'feed', title: f.name, |
| 92 | source: `${f.city}, ${f.country}`, |
| 93 | lat: f.lat, lng: f.lng, |
| 94 | feedUrl: f.url, severity: 'LOW', category: f.category, |
| 95 | }); |
| 96 | }); |
| 97 | |
| 98 | const filtered = filter === 'all' ? alerts : |
| 99 | filter === 'news' ? alerts.filter(a => a.type === 'news') : |
| 100 | filter === 'quakes' ? alerts.filter(a => a.type === 'quake') : |
| 101 | alerts.filter(a => a.type === 'feed'); |
| 102 | |
| 103 | const getIcon = (type: string) => { |
| 104 | switch (type) { |
| 105 | case 'news': return Newspaper; |
| 106 | case 'quake': return AlertTriangle; |
| 107 | case 'feed': return Radio; |
| 108 | default: return Newspaper; |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | return ( |
| 113 | <motion.div |
| 114 | initial={{ opacity: 0, x: 20 }} |
| 115 | animate={{ opacity: 1, x: 0 }} |
| 116 | transition={{ delay: 0.5, duration: 0.6 }} |
| 117 | className={`glass-panel flex flex-col overflow-hidden pointer-events-auto shrink-0 resize-y min-h-[200px] transition-all duration-300 ${maximized ? 'fixed inset-4 z-[9999] bg-[#0a0a09]/95 backdrop-blur-3xl' : ''}`} |
| 118 | > |
| 119 | <button |
| 120 | onClick={() => setExpanded(!expanded)} |
| 121 | className="flex items-center justify-between px-3 py-2 hover:bg-[var(--hover-accent)] transition-colors" |
| 122 | > |
| 123 | <div className="flex items-center gap-2"> |
| 124 | <Radio className="w-3.5 h-3.5 text-[#FF4081]" /> |
| 125 | <span className="hud-text text-[10px] text-[var(--text-primary)]">LIVE ALERTS</span> |
| 126 | <span className="gotham-tag gotham-tag--high" style={{ fontSize: '7px', padding: '1px 5px' }}>{alerts.filter(a => a.type === 'news' || a.type === 'quake').length}</span> |
| 127 | <span className="gotham-tag gotham-tag--info" style={{ fontSize: '7px', padding: '1px 4px' }}>{BUILTIN_FEEDS.length} FEEDS</span> |
| 128 | </div> |
| 129 | <div className="flex items-center gap-2"> |
| 130 | <div className="w-1.5 h-1.5 rounded-full bg-[#FF4081] animate-osiris-pulse" /> |
| 131 | <button onClick={(e) => { e.stopPropagation(); setMaximized(!maximized); if (!expanded && !maximized) setExpanded(true); }} className="hover:text-white transition-colors" title={maximized ? "Restore" : "Maximize"}> |
| 132 | {maximized ? <Minimize2 className="w-3 h-3 text-[var(--text-muted)]" /> : <Maximize2 className="w-3 h-3 text-[var(--text-muted)]" />} |
| 133 | </button> |
| 134 | {expanded ? <ChevronUp className="w-3.5 h-3.5 text-[var(--text-muted)]" /> : <ChevronDown className="w-3.5 h-3.5 text-[var(--text-muted)]" />} |
| 135 | </div> |
| 136 | </button> |
| 137 | |
| 138 | <AnimatePresence> |
| 139 | {expanded && ( |
| 140 | <motion.div |
| 141 | initial={{ height: 0, opacity: 0 }} |
| 142 | animate={{ height: 'auto', opacity: 1 }} |
| 143 | exit={{ height: 0, opacity: 0 }} |
| 144 | transition={{ duration: 0.2 }} |
| 145 | className="overflow-hidden px-2 pb-2 flex flex-col flex-1 h-full min-h-0" |
| 146 | > |
| 147 | {/* Filters */} |
| 148 | <div className="flex gap-1 mb-2"> |
| 149 | {(['all', 'news', 'quakes', 'feeds'] as const).map(f => ( |
| 150 | <button |
| 151 | key={f} |
| 152 | onClick={() => setFilter(f)} |
| 153 | className={`px-2 py-1 rounded text-[9px] font-mono tracking-wider transition-all ${filter === f ? 'bg-[var(--hover-accent)] text-[var(--text-primary)] border border-[var(--border-primary)]' : 'text-[var(--text-muted)] border border-transparent hover:text-[var(--text-secondary)]'}`} |
| 154 | > |
| 155 | {f.toUpperCase()} |
| 156 | </button> |
| 157 | ))} |
| 158 | </div> |
| 159 | |
| 160 | {/* Alert List */} |
| 161 | <div className="space-y-0.5 overflow-y-auto styled-scrollbar flex-1 pb-4"> |
| 162 | {filtered.map((alert, i) => { |
| 163 | const Icon = getIcon(alert.type); |
| 164 | const sevColor = RISK_COLORS[alert.severity] || '#FFD700'; |
| 165 | return ( |
| 166 | <div |
| 167 | key={i} |
| 168 | onClick={() => { |
| 169 | if (alert.lat !== undefined && alert.lng !== undefined) { |
| 170 | onLocate(alert.lat, alert.lng); |
| 171 | } |
| 172 | if (alert.feedUrl && onWatchFeed) { |
| 173 | onWatchFeed(alert.feedUrl, alert.title); |
| 174 | } |
| 175 | }} |
| 176 | className="w-full text-left p-2 rounded-lg hover:bg-[var(--hover-accent)] transition-all border border-transparent hover:border-[var(--border-primary)] group cursor-default" |
| 177 | > |
| 178 | <div className="flex items-start gap-2"> |
| 179 | {/* Severity indicator */} |
| 180 | <div className="flex-shrink-0 mt-0.5"> |
| 181 | <div className="w-2 h-2 rounded-full" style={{ backgroundColor: sevColor, boxShadow: `0 0 6px ${sevColor}60` }} /> |
| 182 | </div> |
| 183 | |
| 184 | <div className="flex-1 min-w-0"> |
| 185 | <div className="flex items-center gap-1.5 mb-1"> |
| 186 | <Icon className="w-3 h-3 flex-shrink-0" style={{ color: sevColor }} /> |
| 187 | <span className={`text-[10px] font-mono text-[var(--text-primary)] ${alert.type === 'news' ? 'line-clamp-4 leading-snug' : 'truncate leading-tight'}`}> |
| 188 | {alert.description || alert.title} |
| 189 | </span> |
| 190 | </div> |
| 191 | <div className="flex items-center justify-between"> |
| 192 | <div className="flex items-center gap-2"> |
| 193 | <span className="text-[8px] font-mono text-[var(--text-muted)]">{alert.source}</span> |
| 194 | {alert.time && ( |
| 195 | <span className="text-[8px] font-mono text-[var(--text-muted)] flex items-center gap-0.5"> |
| 196 | <Clock className="w-2 h-2" /> |
| 197 | {new Date(alert.time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })} |
| 198 | </span> |
| 199 | )} |
| 200 | </div> |
| 201 | {alert.url && ( |
| 202 | <a |
| 203 | href={alert.url} |
| 204 | target="_blank" |
| 205 | rel="noopener noreferrer" |
| 206 | className="text-[8px] font-mono text-[var(--cyan-primary)] hover:underline" |
| 207 | onClick={(e) => e.stopPropagation()} |
| 208 | > |
| 209 | SOURCE |
| 210 | </a> |
| 211 | )} |
| 212 | </div> |
| 213 | </div> |
| 214 | |
| 215 | {/* Fly-to icon */} |
| 216 | {alert.lat !== undefined && ( |
| 217 | <MapPin className="w-3 h-3 text-[var(--text-muted)] opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0 mt-0.5" /> |
| 218 | )} |
| 219 | </div> |
| 220 | </div> |
| 221 | ); |
| 222 | })} |
| 223 | {filtered.length === 0 && ( |
| 224 | <div className="text-center py-4 text-[10px] font-mono text-[var(--text-muted)]"> |
| 225 | No alerts for this filter |
| 226 | </div> |
| 227 | )} |
| 228 | </div> |
| 229 | </motion.div> |
| 230 | )} |
| 231 | </AnimatePresence> |
| 232 | </motion.div> |
| 233 | ); |
| 234 | } |