Elffuss BraidHub

kikocis/osiris public

35361bd0a86f · 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' },
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 || !data[dk]) return null;
92 return Array.isArray(data[dk]) ? data[dk].length : null;
93 };
94 const totalEntities = ALL_LAYERS.reduce((s: number, l: any) => s + (getCount(l.dataKey) || 0), 0);
95 const activeCount = Object.values(activeLayers).filter(Boolean).length;
96
97 const toggleGroup = (groupLabel: string) => {
98 setExpandedGroups(prev => ({ ...prev, [groupLabel]: !prev[groupLabel] }));
99 };
100
101 const toggleAllInGroup = (group: typeof LAYER_GROUPS[0]) => {
102 const allActive = group.layers.every(l => activeLayers[l.key]);
103 setActiveLayers((prev: any) => {
104 const next = { ...prev };
105 group.layers.forEach(l => { next[l.key] = !allActive; });
106 return next;
107 });
108 };
109
110 return (
111 <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">
112 {/* Header */}
113 <div className="flex items-center justify-between mb-3">
114 <div className="flex items-center gap-2">
115 <div className="relative">
116 <Eye className="w-3.5 h-3.5 text-[var(--gold-primary)]" />
117 <div className="absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full bg-[var(--alert-green)] animate-osiris-pulse" />
118 </div>
119 <span className="hud-text text-[12px] text-[var(--text-primary)] tracking-widest">DATA LAYERS</span>
120 </div>
121 <div className="flex items-center gap-1.5">
122 <span className={`gotham-tag ${activeCount > 10 ? 'gotham-tag--critical' : activeCount > 5 ? 'gotham-tag--high' : 'gotham-tag--low'}`} style={{ fontSize: '8px', padding: '1px 6px' }}>
123 {activeCount}/{ALL_LAYERS.length}
124 </span>
125 <span className="gotham-tag gotham-tag--info" style={{ fontSize: '7px', padding: '1px 5px' }}>{totalEntities.toLocaleString()} ENT</span>
126 </div>
127 </div>
128
129 {/* Groups */}
130 <div className="space-y-1">
131 {LAYER_GROUPS.map((group) => {
132 const isExpanded = expandedGroups[group.label];
133 const groupActiveCount = group.layers.filter(l => activeLayers[l.key]).length;
134 const allActive = groupActiveCount === group.layers.length;
135 const GroupIcon = group.icon;
136
137 return (
138 <div key={group.label}>
139 {/* Group Header */}
140 <div className="flex items-center gap-1.5">
141 <button
142 onClick={() => toggleGroup(group.label)}
143 className="flex-1 flex items-center gap-2 px-2 py-1.5 rounded-md hover:bg-white/[0.03] transition-colors"
144 >
145 <GroupIcon className="w-3 h-3 flex-shrink-0" style={{ color: group.color }} />
146 <span className="text-[9px] font-mono tracking-[0.15em] text-[var(--text-secondary)] font-bold flex-1 text-left">{group.label}</span>
147 <span className="text-[8px] font-mono tabular-nums" style={{ color: groupActiveCount > 0 ? group.color : 'var(--text-muted)' }}>
148 {groupActiveCount}/{group.layers.length}
149 </span>
150 {isExpanded ? (
151 <ChevronUp className="w-3 h-3 text-[var(--text-muted)]" />
152 ) : (
153 <ChevronDown className="w-3 h-3 text-[var(--text-muted)]" />
154 )}
155 </button>
156 {/* Toggle all in group */}
157 <button
158 onClick={() => toggleAllInGroup(group)}
159 className="p-1 rounded hover:bg-white/[0.05] transition-colors"
160 title={allActive ? 'Disable all' : 'Enable all'}
161 >
162 {allActive ? (
163 <ToggleRight className="w-3.5 h-3.5" style={{ color: group.color }} />
164 ) : (
165 <ToggleLeft className="w-3.5 h-3.5 text-[var(--text-muted)]" />
166 )}
167 </button>
168 </div>
169
170 {/* Layer items */}
171 <AnimatePresence>
172 {isExpanded && (
173 <motion.div
174 initial={{ height: 0, opacity: 0 }}
175 animate={{ height: 'auto', opacity: 1 }}
176 exit={{ height: 0, opacity: 0 }}
177 transition={{ duration: 0.2 }}
178 className="overflow-hidden"
179 >
180 <div className="ml-2 pl-2 border-l border-[var(--border-secondary)]/40 space-y-px">
181 {group.layers.map((layer) => {
182 const Icon = layer.icon;
183 const isActive = activeLayers[layer.key];
184 const count = getCount(layer.dataKey);
185 return (
186 <button
187 key={layer.key}
188 onClick={() => toggle(layer.key)}
189 className={`w-full flex items-center gap-2.5 px-2 py-[5px] rounded-md transition-all duration-200 group ${
190 isActive
191 ? 'bg-white/[0.04] border border-white/[0.06]'
192 : 'border border-transparent hover:bg-white/[0.02]'
193 }`}
194 >
195 {/* Color dot indicator */}
196 <div
197 className={`w-1.5 h-1.5 rounded-full flex-shrink-0 transition-all duration-300 ${isActive ? 'scale-100' : 'scale-50 opacity-30'}`}
198 style={{
199 backgroundColor: layer.color,
200 boxShadow: isActive ? `0 0 6px ${layer.color}60` : 'none',
201 }}
202 />
203 <Icon
204 className="w-3.5 h-3.5 flex-shrink-0 transition-colors duration-200"
205 style={{ color: isActive ? layer.color : 'var(--text-muted)' }}
206 />
207 <span className={`text-[11px] font-mono tracking-wide flex-1 text-left transition-colors duration-200 ${
208 isActive ? 'text-[var(--text-primary)]' : 'text-[var(--text-muted)] group-hover:text-[var(--text-secondary)]'
209 }`}>
210 {layer.label}
211 </span>
212 {count !== null && (
213 <span
214 className="text-[9px] font-mono tabular-nums font-bold transition-colors duration-200"
215 style={{ color: isActive ? layer.color : 'var(--text-muted)' }}
216 >
217 {count.toLocaleString()}
218 </span>
219 )}
220 {/* Toggle switch */}
221 <div className={`layer-toggle ${isActive ? 'active' : ''}`} />
222 </button>
223 );
224 })}
225 </div>
226 </motion.div>
227 )}
228 </AnimatePresence>
229 </div>
230 );
231 })}
232 </div>
233 </motion.div>
234 );
235}
236
237export default memo(LayerPanel);