Elffuss BraidHub

kikocis/osiris public

020dfbb0c4c8 · 10.8 KiBRawPermalink
1'use client';
2
3import { memo, useState } from 'react';
4import { motion, AnimatePresence } from 'framer-motion';
5import {
6 Plane, Satellite, Activity, Globe, Radio, Eye,
7 Shield, Sun, AlertTriangle, Camera, Flame, Target,
8 CloudLightning, Radiation, Tv, Anchor, Ship, Newspaper, Send,
9 ChevronDown, ChevronUp, ToggleLeft, ToggleRight,
10} from 'lucide-react';
11
12interface LayerPanelProps {
13 data: any;
14 activeLayers: any;
15 setActiveLayers: React.Dispatch<React.SetStateAction<any>>;
16}
17
18const LAYER_GROUPS = [
19 {
20 label: 'AVIATION',
21 icon: Plane,
22 color: '#00E5FF',
23 layers: [
24 { key: 'flights', label: 'Commercial', icon: Plane, color: '#00E5FF', dataKey: 'commercial_flights' },
25 { key: 'private', label: 'Private', icon: Plane, color: '#00E676', dataKey: 'private_flights' },
26 { key: 'jets', label: 'Private Jets', icon: Plane, color: '#FF69B4', dataKey: 'private_jets' },
27 { key: 'military', label: 'Military', icon: Shield, color: '#FF3D3D', dataKey: 'military_flights' },
28 ],
29 },
30 {
31 label: 'MARITIME & SPACE',
32 icon: Ship,
33 color: '#00BCD4',
34 layers: [
35 { key: 'maritime', label: 'Maritime / Naval', icon: Ship, color: '#00BCD4', dataKey: 'maritime_ships,maritime_ports,maritime_chokepoints' },
36 { key: 'satellites', label: 'Satellites', icon: Satellite, color: '#D4AF37', dataKey: 'satellites' },
37 ],
38 },
39 {
40 label: 'SURVEILLANCE',
41 icon: Camera,
42 color: '#39FF14',
43 layers: [
44 { key: 'cctv', label: 'CCTV Cameras', icon: Camera, color: '#39FF14', dataKey: 'cameras' },
45 { key: 'live_news', label: 'Live News Feeds', icon: Tv, color: '#FF4081', dataKey: 'live_feeds' },
46 { key: 'news_intel', label: 'SIGINT News (RSS)', icon: Newspaper, color: '#D4AF37', dataKey: 'news' },
47 { key: 'telegram_intel', label: 'Telegram OSINT', icon: Send, color: '#00BFFF', dataKey: 'telegram' },
48 ],
49 },
50 {
51 label: 'NATURAL HAZARDS',
52 icon: Activity,
53 color: '#FF9500',
54 layers: [
55 { key: 'earthquakes', label: 'Earthquakes (24h)', icon: Activity, color: '#FF9500', dataKey: 'earthquakes' },
56 { key: 'fires', label: 'Active Fires', icon: Flame, color: '#FF6B00', dataKey: 'fires' },
57 { key: 'weather', label: 'Severe Weather', icon: CloudLightning, color: '#E040FB', dataKey: 'weather_events' },
58 ],
59 },
60 {
61 label: 'THREATS & INFRA',
62 icon: AlertTriangle,
63 color: '#FF3D3D',
64 layers: [
65 { key: 'infrastructure', label: 'Nuclear Facilities', icon: Radiation, color: '#76FF03', dataKey: 'infrastructure' },
66 { key: 'global_incidents', label: 'Global Incidents', icon: AlertTriangle, color: '#FF3D3D', dataKey: 'gdelt' },
67 { key: 'gps_jamming', label: 'GPS Jamming', icon: Radio, color: '#FF4444', dataKey: 'gps_jamming' },
68 ],
69 },
70 {
71 label: 'DISPLAY',
72 icon: Sun,
73 color: '#448AFF',
74 layers: [
75 { key: 'day_night', label: 'Day / Night Cycle', icon: Sun, color: '#448AFF', dataKey: '' },
76 ],
77 },
78];
79
80// Flat list for backward compat
81const ALL_LAYERS = LAYER_GROUPS.flatMap(g => g.layers);
82
83function LayerPanel({ data, activeLayers, setActiveLayers }: LayerPanelProps) {
84 const [expandedGroups, setExpandedGroups] = useState<Record<string, boolean>>(() => {
85 const initial: Record<string, boolean> = {};
86 LAYER_GROUPS.forEach(g => { initial[g.label] = true; });
87 return initial;
88 });
89
90 const toggle = (key: string) => setActiveLayers((prev: any) => ({ ...prev, [key]: !prev[key] }));
91 const getCount = (dk: string): number | null => {
92 if (!dk) return null;
93 let total = 0;
94 let found = false;
95 for (const k of dk.split(',')) {
96 if (data[k] && Array.isArray(data[k])) {
97 total += data[k].length;
98 found = true;
99 }
100 }
101 return found ? total : null;
102 };
103 const totalEntities = ALL_LAYERS.reduce((s: number, l: any) => s + (getCount(l.dataKey) || 0), 0);
104 const activeCount = Object.values(activeLayers).filter(Boolean).length;
105
106 const toggleGroup = (groupLabel: string) => {
107 setExpandedGroups(prev => ({ ...prev, [groupLabel]: !prev[groupLabel] }));
108 };
109
110 const toggleAllInGroup = (group: typeof LAYER_GROUPS[0]) => {
111 const allActive = group.layers.every(l => activeLayers[l.key]);
112 setActiveLayers((prev: any) => {
113 const next = { ...prev };
114 group.layers.forEach(l => { next[l.key] = !allActive; });
115 return next;
116 });
117 };
118
119 return (
120 <motion.div initial={{ opacity: 0, x: -20 }} animate={{ opacity: 1, x: 0 }} transition={{ delay: 0.3, duration: 0.6 }} className="glass-panel p-3 pointer-events-auto">
121 {/* Header */}
122 <div className="flex items-center justify-between mb-3">
123 <div className="flex items-center gap-2">
124 <div className="relative">
125 <Eye className="w-3.5 h-3.5 text-[var(--gold-primary)]" />
126 <div className="absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-[var(--alert-green)] animate-osiris-pulse" />
127 </div>
128 <span className="hud-text text-[12px] text-[var(--text-primary)] tracking-widest">DATA LAYERS</span>
129 </div>
130 <div className="flex items-center gap-1.5">
131 <span className={`gotham-tag ${activeCount > 10 ? 'gotham-tag--critical' : activeCount > 5 ? 'gotham-tag--high' : 'gotham-tag--low'}`} style={{ fontSize: '8px', padding: '1px 6px' }}>
132 {activeCount}/{ALL_LAYERS.length}
133 </span>
134 <span className="gotham-tag gotham-tag--info" style={{ fontSize: '7px', padding: '1px 5px' }}>{totalEntities.toLocaleString()} ENT</span>
135 </div>
136 </div>
137
138 {/* Groups */}
139 <div className="space-y-1">
140 {LAYER_GROUPS.map((group) => {
141 const isExpanded = expandedGroups[group.label];
142 const groupActiveCount = group.layers.filter(l => activeLayers[l.key]).length;
143 const allActive = groupActiveCount === group.layers.length;
144 const GroupIcon = group.icon;
145
146 return (
147 <div key={group.label}>
148 {/* Group Header */}
149 <div className="flex items-center gap-1.5">
150 <button
151 onClick={() => toggleGroup(group.label)}
152 className="flex-1 flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-white/[0.03] transition-colors"
153 >
154 <GroupIcon className="w-3 h-3 flex-shrink-0" style={{ color: group.color }} />
155 <span className="text-[9px] font-mono tracking-[0.15em] text-[var(--text-secondary)] font-bold flex-1 text-left">{group.label}</span>
156 <span className="text-[8px] font-mono tabular-nums" style={{ color: groupActiveCount > 0 ? group.color : 'var(--text-muted)' }}>
157 {groupActiveCount}/{group.layers.length}
158 </span>
159 {isExpanded ? (
160 <ChevronUp className="w-3 h-3 text-[var(--text-muted)]" />
161 ) : (
162 <ChevronDown className="w-3 h-3 text-[var(--text-muted)]" />
163 )}
164 </button>
165 {/* Toggle all in group */}
166 <button
167 onClick={() => toggleAllInGroup(group)}
168 className="p-1 rounded hover:bg-white/[0.05] transition-colors"
169 title={allActive ? 'Disable all' : 'Enable all'}
170 >
171 {allActive ? (
172 <ToggleRight className="w-3.5 h-3.5" style={{ color: group.color }} />
173 ) : (
174 <ToggleLeft className="w-3.5 h-3.5 text-[var(--text-muted)]" />
175 )}
176 </button>
177 </div>
178
179 {/* Layer items */}
180 <AnimatePresence>
181 {isExpanded && (
182 <motion.div
183 initial={{ height: 0, opacity: 0 }}
184 animate={{ height: 'auto', opacity: 1 }}
185 exit={{ height: 0, opacity: 0 }}
186 transition={{ duration: 0.2 }}
187 className="overflow-hidden"
188 >
189 <div className="ml-2 pl-2 border-l border-[var(--border-secondary)]/40 space-y-px">
190 {group.layers.map((layer) => {
191 const Icon = layer.icon;
192 const isActive = activeLayers[layer.key];
193 const count = getCount(layer.dataKey);
194 return (
195 <button
196 key={layer.key}
197 onClick={() => toggle(layer.key)}
198 className={`w-full flex items-center gap-2.5 px-2 py-[5px] rounded-md transition-all duration-200 group ${
199 isActive
200 ? 'bg-white/[0.04] border border-white/[0.06]'
201 : 'border border-transparent hover:bg-white/[0.02]'
202 }`}
203 >
204 {/* Color dot indicator */}
205 <div
206 className={`w-1.5 h-1.5 rounded-full flex-shrink-0 transition-all duration-300 ${isActive ? 'scale-100' : 'scale-50 opacity-30'}`}
207 style={{
208 backgroundColor: layer.color,
209 boxShadow: isActive ? `0 0 6px ${layer.color}60` : 'none',
210 }}
211 />
212 <Icon
213 className="w-3.5 h-3.5 flex-shrink-0 transition-colors duration-200"
214 style={{ color: isActive ? layer.color : 'var(--text-muted)' }}
215 />
216 <span className={`text-[11px] font-mono tracking-wide flex-1 text-left transition-colors duration-200 ${
217 isActive ? 'text-[var(--text-primary)]' : 'text-[var(--text-muted)] group-hover:text-[var(--text-secondary)]'
218 }`}>
219 {layer.label}
220 </span>
221 {count !== null && (
222 <span
223 className="text-[9px] font-mono tabular-nums font-bold transition-colors duration-200"
224 style={{ color: isActive ? layer.color : 'var(--text-muted)' }}
225 >
226 {count.toLocaleString()}
227 </span>
228 )}
229 {/* Toggle switch */}
230 <div className={`layer-toggle ${isActive ? 'active' : ''}`} />
231 </button>
232 );
233 })}
234 </div>
235 </motion.div>
236 )}
237 </AnimatePresence>
238 </div>
239 );
240 })}
241 </div>
242 </motion.div>
243 );
244}
245
246export default memo(LayerPanel);