Elffuss BraidHub

kikocis/osiris public

09d1cb3093e4 · 13.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 // OSINT Telegram News Feed (from /api/news)
65 if (data.news) {
66 data.news.forEach((a: any) => {
67 alerts.push({
68 type: 'news', title: a.title, description: a.description, source: a.source,
69 lat: a.coords?.[0], lng: a.coords?.[1], time: a.published,
70 severity: (a.risk_score ?? 1) >= 8 ? 'CRITICAL' : (a.risk_score ?? 1) >= 6 ? 'HIGH' : (a.risk_score ?? 1) >= 4 ? 'ELEVATED' : 'LOW',
71 url: a.link,
72 });
73 });
74 }
75
76 // Earthquakes
77 if (data.earthquakes) {
78 data.earthquakes.slice(0, 5).forEach((eq: any) => {
79 alerts.push({
80 type: 'quake', title: `M${eq.magnitude} - ${eq.place}`, source: 'USGS',
81 lat: eq.lat, lng: eq.lng, time: eq.time,
82 severity: eq.magnitude >= 6 ? 'CRITICAL' : eq.magnitude >= 4.5 ? 'HIGH' : 'MODERATE',
83 });
84 });
85 }
86
87 // Built-in live feeds (always present)
88 BUILTIN_FEEDS.forEach(f => {
89 alerts.push({
90 type: 'feed', title: f.name,
91 source: `${f.city}, ${f.country}`,
92 lat: f.lat, lng: f.lng,
93 feedUrl: f.url, severity: 'LOW', category: f.category,
94 });
95 });
96
97 const filtered = filter === 'all' ? alerts :
98 filter === 'news' ? alerts.filter(a => a.type === 'news') :
99 filter === 'quakes' ? alerts.filter(a => a.type === 'quake') :
100 alerts.filter(a => a.type === 'feed');
101
102 const getIcon = (type: string) => {
103 switch (type) {
104 case 'news': return Newspaper;
105 case 'quake': return AlertTriangle;
106 case 'feed': return Radio;
107 default: return Newspaper;
108 }
109 };
110
111 return (
112 <motion.div
113 initial={{ opacity: 0, x: 20 }}
114 animate={{ opacity: 1, x: 0 }}
115 transition={{ delay: 0.5, duration: 0.6 }}
116 className="glass-panel flex flex-col overflow-hidden pointer-events-auto"
117 >
118 <button
119 onClick={() => setExpanded(!expanded)}
120 className="flex items-center justify-between px-3 py-2 hover:bg-[var(--hover-accent)] transition-colors"
121 >
122 <div className="flex items-center gap-2">
123 <Radio className="w-3.5 h-3.5 text-[#FF4081]" />
124 <span className="hud-text text-[10px] text-[var(--text-primary)]">LIVE ALERTS</span>
125 <span className="gotham-tag gotham-tag--high" style={{ fontSize: '7px', padding: '1px 5px' }}>{alerts.filter(a => a.type === 'news' || a.type === 'quake').length}</span>
126 <span className="gotham-tag gotham-tag--info" style={{ fontSize: '7px', padding: '1px 4px' }}>{BUILTIN_FEEDS.length} FEEDS</span>
127 </div>
128 <div className="flex items-center gap-2">
129 <div className="w-1.5 h-1.5 rounded-full bg-[#FF4081] animate-osiris-pulse" />
130 {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)]" />}
131 </div>
132 </button>
133
134 <AnimatePresence>
135 {expanded && (
136 <motion.div
137 initial={{ height: 0, opacity: 0 }}
138 animate={{ height: 'auto', opacity: 1 }}
139 exit={{ height: 0, opacity: 0 }}
140 transition={{ duration: 0.2 }}
141 className="overflow-hidden px-2 pb-2"
142 >
143 {/* Filters */}
144 <div className="flex gap-1 mb-2">
145 {(['all', 'news', 'quakes', 'feeds'] as const).map(f => (
146 <button
147 key={f}
148 onClick={() => setFilter(f)}
149 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)]'}`}
150 >
151 {f.toUpperCase()}
152 </button>
153 ))}
154 </div>
155
156 {/* Alert List */}
157 <div className="space-y-0.5 max-h-[180px] overflow-y-auto styled-scrollbar">
158 {filtered.map((alert, i) => {
159 const Icon = getIcon(alert.type);
160 const sevColor = RISK_COLORS[alert.severity] || '#FFD700';
161 return (
162 <div
163 key={i}
164 onClick={() => {
165 if (alert.lat !== undefined && alert.lng !== undefined) {
166 onLocate(alert.lat, alert.lng);
167 }
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 cursor-default"
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-1">
182 <Icon className="w-3 h-3 flex-shrink-0" style={{ color: sevColor }} />
183 <span className={`text-[10px] font-mono text-[var(--text-primary)] ${alert.type === 'news' ? 'line-clamp-4 leading-snug' : 'truncate leading-tight'}`}>
184 {alert.description || alert.title}
185 </span>
186 </div>
187 <div className="flex items-center justify-between">
188 <div className="flex items-center gap-2">
189 <span className="text-[8px] font-mono text-[var(--text-muted)]">{alert.source}</span>
190 {alert.time && (
191 <span className="text-[8px] font-mono text-[var(--text-muted)] flex items-center gap-0.5">
192 <Clock className="w-2 h-2" />
193 {new Date(alert.time).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
194 </span>
195 )}
196 </div>
197 {alert.url && (
198 <a
199 href={alert.url}
200 target="_blank"
201 rel="noopener noreferrer"
202 className="text-[8px] font-mono text-[var(--cyan-primary)] hover:underline"
203 onClick={(e) => e.stopPropagation()}
204 >
205 SOURCE
206 </a>
207 )}
208 </div>
209 </div>
210
211 {/* Fly-to icon */}
212 {alert.lat !== undefined && (
213 <MapPin className="w-3 h-3 text-[var(--text-muted)] opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0 mt-0.5" />
214 )}
215 </div>
216 </div>
217 );
218 })}
219 {filtered.length === 0 && (
220 <div className="text-center py-4 text-[10px] font-mono text-[var(--text-muted)]">
221 No alerts for this filter
222 </div>
223 )}
224 </div>
225 </motion.div>
226 )}
227 </AnimatePresence>
228 </motion.div>
229 );
230}