Elffuss BraidHub

kikocis/osiris public

f68fe51a6edb · 10.7 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,
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 ],
48 },
49 {
50 label: 'NATURAL HAZARDS',
51 icon: Activity,
52 color: '#FF9500',
53 layers: [
54 { key: 'earthquakes', label: 'Earthquakes (24h)', icon: Activity, color: '#FF9500', dataKey: 'earthquakes' },
55 { key: 'fires', label: 'Active Fires', icon: Flame, color: '#FF6B00', dataKey: 'fires' },
56 { key: 'weather', label: 'Severe Weather', icon: CloudLightning, color: '#E040FB', dataKey: 'weather_events' },
57 ],
58 },
59 {
60 label: 'THREATS & INFRA',
61 icon: AlertTriangle,
62 color: '#FF3D3D',
63 layers: [
64 { key: 'infrastructure', label: 'Nuclear Facilities', icon: Radiation, color: '#76FF03', dataKey: 'infrastructure' },
65 { key: 'global_incidents', label: 'Global Incidents', icon: AlertTriangle, color: '#FF3D3D', dataKey: 'gdelt' },
66 { key: 'gps_jamming', label: 'GPS Jamming', icon: Radio, color: '#FF4444', dataKey: 'gps_jamming' },
67 ],
68 },
69 {
70 label: 'DISPLAY',
71 icon: Sun,
72 color: '#448AFF',
73 layers: [
74 { key: 'day_night', label: 'Day / Night Cycle', icon: Sun, color: '#448AFF', dataKey: '' },
75 ],
76 },
77];
78
79// Flat list for backward compat
80const ALL_LAYERS = LAYER_GROUPS.flatMap(g => g.layers);
81
82function LayerPanel({ data, activeLayers, setActiveLayers }: LayerPanelProps) {
83 const [expandedGroups, setExpandedGroups] = useState<Record<string, boolean>>(() => {
84 const initial: Record<string, boolean> = {};
85 LAYER_GROUPS.forEach(g => { initial[g.label] = true; });
86 return initial;
87 });
88
89 const toggle = (key: string) => setActiveLayers((prev: any) => ({ ...prev, [key]: !prev[key] }));
90 const getCount = (dk: string): number | null => {
91 if (!dk) return null;
92 let total = 0;
93 let found = false;
94 for (const k of dk.split(',')) {
95 if (data[k] && Array.isArray(data[k])) {
96 total += data[k].length;
97 found = true;
98 }
99 }
100 return found ? total : null;
101 };
102 const totalEntities = ALL_LAYERS.reduce((s: number, l: any) => s + (getCount(l.dataKey) || 0), 0);
103 const activeCount = Object.values(activeLayers).filter(Boolean).length;
104
105 const toggleGroup = (groupLabel: string) => {
106 setExpandedGroups(prev => ({ ...prev, [groupLabel]: !prev[groupLabel] }));
107 };
108
109 const toggleAllInGroup = (group: typeof LAYER_GROUPS[0]) => {
110 const allActive = group.layers.every(l => activeLayers[l.key]);
111 setActiveLayers((prev: any) => {
112 const next = { ...prev };
113 group.layers.forEach(l => { next[l.key] = !allActive; });
114 return next;
115 });
116 };
117
118 return (
119 <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">
120 {/* Header */}
121 <div className="flex items-center justify-between mb-3">
122 <div className="flex items-center gap-2">
123 <div className="relative">
124 <Eye className="w-3.5 h-3.5 text-[var(--gold-primary)]" />
125 <div className="absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-[var(--alert-green)] animate-osiris-pulse" />
126 </div>
127 <span className="hud-text text-[12px] text-[var(--text-primary)] tracking-widest">DATA LAYERS</span>
128 </div>
129 <div className="flex items-center gap-1.5">
130 <span className={`gotham-tag ${activeCount > 10 ? 'gotham-tag--critical' : activeCount > 5 ? 'gotham-tag--high' : 'gotham-tag--low'}`} style={{ fontSize: '8px', padding: '1px 6px' }}>
131 {activeCount}/{ALL_LAYERS.length}
132 </span>
133 <span className="gotham-tag gotham-tag--info" style={{ fontSize: '7px', padding: '1px 5px' }}>{totalEntities.toLocaleString()} ENT</span>
134 </div>
135 </div>
136
137 {/* Groups */}
138 <div className="space-y-1">
139 {LAYER_GROUPS.map((group) => {
140 const isExpanded = expandedGroups[group.label];
141 const groupActiveCount = group.layers.filter(l => activeLayers[l.key]).length;
142 const allActive = groupActiveCount === group.layers.length;
143 const GroupIcon = group.icon;
144
145 return (
146 <div key={group.label}>
147 {/* Group Header */}
148 <div className="flex items-center gap-1.5">
149 <button
150 onClick={() => toggleGroup(group.label)}
151 className="flex-1 flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-white/[0.03] transition-colors"
152 >
153 <GroupIcon className="w-3 h-3 flex-shrink-0" style={{ color: group.color }} />
154 <span className="text-[9px] font-mono tracking-[0.15em] text-[var(--text-secondary)] font-bold flex-1 text-left">{group.label}</span>
155 <span className="text-[8px] font-mono tabular-nums" style={{ color: groupActiveCount > 0 ? group.color : 'var(--text-muted)' }}>
156 {groupActiveCount}/{group.layers.length}
157 </span>
158 {isExpanded ? (
159 <ChevronUp className="w-3 h-3 text-[var(--text-muted)]" />
160 ) : (
161 <ChevronDown className="w-3 h-3 text-[var(--text-muted)]" />
162 )}
163 </button>
164 {/* Toggle all in group */}
165 <button
166 onClick={() => toggleAllInGroup(group)}
167 className="p-1 rounded hover:bg-white/[0.05] transition-colors"
168 title={allActive ? 'Disable all' : 'Enable all'}
169 >
170 {allActive ? (
171 <ToggleRight className="w-3.5 h-3.5" style={{ color: group.color }} />
172 ) : (
173 <ToggleLeft className="w-3.5 h-3.5 text-[var(--text-muted)]" />
174 )}
175 </button>
176 </div>
177
178 {/* Layer items */}
179 <AnimatePresence>
180 {isExpanded && (
181 <motion.div
182 initial={{ height: 0, opacity: 0 }}
183 animate={{ height: 'auto', opacity: 1 }}
184 exit={{ height: 0, opacity: 0 }}
185 transition={{ duration: 0.2 }}
186 className="overflow-hidden"
187 >
188 <div className="ml-2 pl-2 border-l border-[var(--border-secondary)]/40 space-y-px">
189 {group.layers.map((layer) => {
190 const Icon = layer.icon;
191 const isActive = activeLayers[layer.key];
192 const count = getCount(layer.dataKey);
193 return (
194 <button
195 key={layer.key}
196 onClick={() => toggle(layer.key)}
197 className={`w-full flex items-center gap-2.5 px-2 py-[5px] rounded-md transition-all duration-200 group ${
198 isActive
199 ? 'bg-white/[0.04] border border-white/[0.06]'
200 : 'border border-transparent hover:bg-white/[0.02]'
201 }`}
202 >
203 {/* Color dot indicator */}
204 <div
205 className={`w-1.5 h-1.5 rounded-full flex-shrink-0 transition-all duration-300 ${isActive ? 'scale-100' : 'scale-50 opacity-30'}`}
206 style={{
207 backgroundColor: layer.color,
208 boxShadow: isActive ? `0 0 6px ${layer.color}60` : 'none',
209 }}
210 />
211 <Icon
212 className="w-3.5 h-3.5 flex-shrink-0 transition-colors duration-200"
213 style={{ color: isActive ? layer.color : 'var(--text-muted)' }}
214 />
215 <span className={`text-[11px] font-mono tracking-wide flex-1 text-left transition-colors duration-200 ${
216 isActive ? 'text-[var(--text-primary)]' : 'text-[var(--text-muted)] group-hover:text-[var(--text-secondary)]'
217 }`}>
218 {layer.label}
219 </span>
220 {count !== null && (
221 <span
222 className="text-[9px] font-mono tabular-nums font-bold transition-colors duration-200"
223 style={{ color: isActive ? layer.color : 'var(--text-muted)' }}
224 >
225 {count.toLocaleString()}
226 </span>
227 )}
228 {/* Toggle switch */}
229 <div className={`layer-toggle ${isActive ? 'active' : ''}`} />
230 </button>
231 );
232 })}
233 </div>
234 </motion.div>
235 )}
236 </AnimatePresence>
237 </div>
238 );
239 })}
240 </div>
241 </motion.div>
242 );
243}
244
245export default memo(LayerPanel);