Elffuss BraidHub

kikocis/osiris public

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