Elffuss BraidHub

kikocis/osiris public

c867dff8b92f · 12.7 KiBRawPermalink
1'use client';
2
3import { useState } from 'react';
4import { motion, AnimatePresence } from 'framer-motion';
5import {
6 ChevronDown, ChevronUp, MapPin, ExternalLink, AlertTriangle,
7 Newspaper, Clock, Radio,
8} from 'lucide-react';
9
10interface LiveAlertsProps {
11 data: any;
12 onLocate: (lat: number, lng: number) => void;
13 onWatchFeed?: (url: string, name: string) => void;
14}
15
16const RISK_COLORS: Record<string, string> = {
17 HIGH: '#FF3D3D',
18 CRITICAL: '#FF1744',
19 ELEVATED: '#FF9500',
20 MODERATE: '#FFD700',
21 LOW: '#00E676',
22};
23
24export default function LiveAlerts({ data, onLocate, onWatchFeed }: LiveAlertsProps) {
25 const [expanded, setExpanded] = useState(true);
26 const [filter, setFilter] = useState<'all' | 'news' | 'quakes' | 'feeds'>('all');
27
28 // Built-in live feeds — verified video IDs (synced with /api/live-news)
29 const BUILTIN_FEEDS = [
30 // ── North America ──
31 { 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' },
32 { 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' },
33 { 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' },
34 { 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' },
35 { 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' },
36 { 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' },
37 // ── Europe ──
38 { 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' },
39 { 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' },
40 { 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' },
41 { 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' },
42 { 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' },
43 { 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' },
44 // ── Middle East ──
45 { 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' },
46 { 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' },
47 { 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' },
48 // ── Asia Pacific ──
49 { 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' },
50 { 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' },
51 { 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' },
52 { 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' },
53 { 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' },
54 // ── Africa ──
55 { 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' },
56 { 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' },
57 // ── Latin America ──
58 { 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' },
59 ];
60
61 // Build unified alert feed
62 const alerts: any[] = [];
63
64 // News articles with locations (from /api/news)
65 if (data.news) {
66 data.news.slice(0, 10).forEach((a: any) => {
67 if (a.coords?.length === 2) {
68 alerts.push({
69 type: 'news', title: a.title, 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
78 // Earthquakes
79 if (data.earthquakes) {
80 data.earthquakes.slice(0, 5).forEach((eq: any) => {
81 alerts.push({
82 type: 'quake', title: `M${eq.magnitude} - ${eq.place}`, source: 'USGS',
83 lat: eq.lat, lng: eq.lng, time: eq.time,
84 severity: eq.magnitude >= 6 ? 'CRITICAL' : eq.magnitude >= 4.5 ? 'HIGH' : 'MODERATE',
85 });
86 });
87 }
88
89 // Built-in live feeds (always present)
90 BUILTIN_FEEDS.forEach(f => {
91 alerts.push({
92 type: 'feed', title: f.name,
93 source: `${f.city}, ${f.country}`,
94 lat: f.lat, lng: f.lng,
95 feedUrl: f.url, severity: 'LOW', category: f.category,
96 });
97 });
98
99 const filtered = filter === 'all' ? alerts :
100 filter === 'news' ? alerts.filter(a => a.type === 'news') :
101 filter === 'quakes' ? alerts.filter(a => a.type === 'quake') :
102 alerts.filter(a => a.type === 'feed');
103
104 const getIcon = (type: string) => {
105 switch (type) {
106 case 'news': return Newspaper;
107 case 'quake': return AlertTriangle;
108 case 'feed': return Radio;
109 default: return Newspaper;
110 }
111 };
112
113 return (
114 <motion.div
115 initial={{ opacity: 0, x: 20 }}
116 animate={{ opacity: 1, x: 0 }}
117 transition={{ delay: 0.5, duration: 0.6 }}
118 className="glass-panel flex flex-col overflow-hidden pointer-events-auto"
119 >
120 <button
121 onClick={() => setExpanded(!expanded)}
122 className="flex items-center justify-between px-3 py-2 hover:bg-[var(--hover-accent)] transition-colors"
123 >
124 <div className="flex items-center gap-2">
125 <Radio className="w-3.5 h-3.5 text-[#FF4081]" />
126 <span className="hud-text text-[10px] text-[var(--text-primary)]">LIVE ALERTS</span>
127 <span className="gotham-tag gotham-tag--high" style={{ fontSize: '7px', padding: '1px 5px' }}>{alerts.filter(a => a.type === 'news' || a.type === 'quake').length}</span>
128 <span className="gotham-tag gotham-tag--info" style={{ fontSize: '7px', padding: '1px 4px' }}>{BUILTIN_FEEDS.length} FEEDS</span>
129 </div>
130 <div className="flex items-center gap-2">
131 <div className="w-1.5 h-1.5 rounded-full bg-[#FF4081] animate-osiris-pulse" />
132 {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)]" />}
133 </div>
134 </button>
135
136 <AnimatePresence>
137 {expanded && (
138 <motion.div
139 initial={{ height: 0, opacity: 0 }}
140 animate={{ height: 'auto', opacity: 1 }}
141 exit={{ height: 0, opacity: 0 }}
142 transition={{ duration: 0.2 }}
143 className="overflow-hidden px-2 pb-2"
144 >
145 {/* Filters */}
146 <div className="flex gap-1 mb-2">
147 {(['all', 'news', 'quakes', 'feeds'] as const).map(f => (
148 <button
149 key={f}
150 onClick={() => setFilter(f)}
151 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)]'}`}
152 >
153 {f.toUpperCase()}
154 </button>
155 ))}
156 </div>
157
158 {/* Alert List */}
159 <div className="space-y-0.5 max-h-[180px] overflow-y-auto styled-scrollbar">
160 {filtered.map((alert, i) => {
161 const Icon = getIcon(alert.type);
162 const sevColor = RISK_COLORS[alert.severity] || '#FFD700';
163 return (
164 <button
165 key={i}
166 onClick={() => {
167 onLocate(alert.lat, alert.lng);
168 if (alert.feedUrl && onWatchFeed) {
169 onWatchFeed(alert.feedUrl, alert.title);
170 }
171 }}
172 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"
173 >
174 <div className="flex items-start gap-2">
175 {/* Severity indicator */}
176 <div className="flex-shrink-0 mt-0.5">
177 <div className="w-2 h-2 rounded-full" style={{ backgroundColor: sevColor, boxShadow: `0 0 6px ${sevColor}60` }} />
178 </div>
179
180 <div className="flex-1 min-w-0">
181 <div className="flex items-center gap-1.5 mb-0.5">
182 <Icon className="w-3 h-3 flex-shrink-0" style={{ color: sevColor }} />
183 <span className="text-[10px] font-mono text-[var(--text-primary)] truncate leading-tight">{alert.title}</span>
184 </div>
185 <div className="flex items-center gap-2">
186 <span className="text-[8px] font-mono text-[var(--text-muted)]">{alert.source}</span>
187 {alert.time && (
188 <span className="text-[8px] font-mono text-[var(--text-muted)] flex items-center gap-0.5">
189 <Clock className="w-2 h-2" />
190 {new Date(alert.time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
191 </span>
192 )}
193 </div>
194 </div>
195
196 {/* Fly-to icon */}
197 <MapPin className="w-3 h-3 text-[var(--text-muted)] opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0 mt-0.5" />
198 </div>
199 </button>
200 );
201 })}
202 {filtered.length === 0 && (
203 <div className="text-center py-4 text-[10px] font-mono text-[var(--text-muted)]">
204 No alerts for this filter
205 </div>
206 )}
207 </div>
208 </motion.div>
209 )}
210 </AnimatePresence>
211 </motion.div>
212 );
213}