Elffuss BraidHub

kikocis/osiris public

master · 6.1 KiBRawPermalink
1'use client';
2
3import { useState } from 'react';
4import { motion, AnimatePresence } from 'framer-motion';
5import {
6 TrendingUp, TrendingDown, ChevronDown, ChevronUp, BarChart3,
7 Zap, Shield, Droplets, Gem, Bitcoin, LineChart, Maximize2, Minimize2
8} from 'lucide-react';
9
10interface MarketsPanelProps { data: any; spaceWeather?: any; }
11
12const SECTIONS = [
13 { key: 'indices', label: 'INDICES', icon: LineChart },
14 { key: 'stocks', label: 'DEFENSE', icon: Shield },
15 { key: 'oil', label: 'ENERGY', icon: Droplets },
16 { key: 'commodities', label: 'COMMODITIES', icon: Gem },
17 { key: 'crypto', label: 'CRYPTO', icon: Bitcoin },
18];
19
20function Ticker({ name, data: d }: { name: string; data: any }) {
21 if (!d) return null;
22 return (
23 <div className="flex items-center justify-between py-1.5 px-2 rounded hover:bg-[var(--hover-accent)] transition-colors">
24 <span className="text-[10px] font-mono text-[var(--text-secondary)] tracking-wide">{name}</span>
25 <div className="flex items-center gap-2">
26 <span className="text-[11px] font-mono font-bold text-[var(--text-primary)] tabular-nums">
27 {d.price >= 1000 ? `${(d.price / 1000).toFixed(1)}K` : d.price?.toFixed(2)}
28 </span>
29 <span className={`text-[9px] font-mono font-bold flex items-center gap-0.5 ${d.up ? 'text-[var(--alert-green)]' : 'text-[var(--alert-red)]'}`}>
30 {d.up ? <TrendingUp className="w-3 h-3" /> : <TrendingDown className="w-3 h-3" />}
31 {d.change_percent > 0 ? '+' : ''}{d.change_percent?.toFixed(2)}%
32 </span>
33 </div>
34 </div>
35 );
36}
37
38export default function MarketsPanel({ data, spaceWeather }: MarketsPanelProps) {
39 const [expanded, setExpanded] = useState(true);
40 const [maximized, setMaximized] = useState(false);
41 const [activeSection, setActiveSection] = useState('stocks');
42 const markets = data.markets || {};
43
44 return (
45 <motion.div initial={{ opacity: 0, x: -20 }} animate={{ opacity: 1, x: 0 }} transition={{ delay: 0.6, duration: 0.6 }} className="glass-panel p-3 pointer-events-auto">
46 <button onClick={() => setExpanded(!expanded)} className="flex items-center justify-between w-full mb-2">
47 <div className="flex items-center gap-2">
48 <BarChart3 className="w-3.5 h-3.5 text-[var(--gold-primary)]" />
49 <span className="hud-text text-[12px] text-[var(--text-primary)]">MARKETS & INTEL</span>
50 <span className="gotham-tag gotham-tag--low" style={{ fontSize: '7px', padding: '1px 4px' }}>LIVE</span>
51 </div>
52 <div className="flex items-center gap-2">
53 <div className="w-1.5 h-1.5 rounded-full bg-[var(--alert-green)] animate-osiris-pulse" />
54 {expanded ? <ChevronUp className="w-3 h-3 text-[var(--text-muted)]" /> : <ChevronDown className="w-3 h-3 text-[var(--text-muted)]" />}
55 </div>
56 </button>
57
58 <AnimatePresence>
59 {expanded && (
60 <motion.div initial={{ height: 0, opacity: 0 }} animate={{ height: 'auto', opacity: 1 }} exit={{ height: 0, opacity: 0 }} transition={{ duration: 0.2 }}>
61 {/* Space Weather Banner */}
62 {spaceWeather && (
63 <div className="mb-2 p-2 rounded-lg border" style={{ borderColor: `${spaceWeather.storm_color}33`, background: `${spaceWeather.storm_color}08` }}>
64 <div className="flex items-center justify-between">
65 <div className="flex items-center gap-1.5">
66 <Zap className="w-3 h-3" style={{ color: spaceWeather.storm_color }} />
67 <span className="text-[10px] font-mono tracking-widest text-[var(--text-muted)]">SPACE WEATHER</span>
68 </div>
69 <span className="text-[10px] font-mono font-bold" style={{ color: spaceWeather.storm_color }}>
70 Kp {spaceWeather.kp_index} — {spaceWeather.storm_level}
71 </span>
72 </div>
73 {spaceWeather.solar_flares?.length > 0 && (
74 <div className="mt-1 text-[8px] font-mono text-[var(--text-muted)]">
75 Latest flare: {spaceWeather.solar_flares[0].class}
76 </div>
77 )}
78 </div>
79 )}
80
81 {/* Section Tabs — icons instead of emojis */}
82 <div className="flex gap-0.5 mb-2 overflow-x-auto">
83 {SECTIONS.map(s => {
84 const Icon = s.icon;
85 return (
86 <button key={s.key} onClick={() => setActiveSection(s.key)}
87 className={`flex items-center gap-1 px-2.5 py-1.5 rounded text-[9px] font-mono tracking-wider whitespace-nowrap transition-all ${activeSection === s.key ? 'bg-[var(--hover-accent)] text-[var(--gold-primary)] border border-[var(--border-primary)]' : 'text-[var(--text-muted)] hover:text-[var(--text-secondary)] border border-transparent'}`}>
88 <Icon className="w-3 h-3" />
89 {s.label}
90 </button>
91 );
92 })}
93 </div>
94
95 {/* SCM Alerts from Markets API */}
96 {markets.scm_alerts && markets.scm_alerts.length > 0 && (
97 <div className="mb-2 space-y-1">
98 {markets.scm_alerts.map((alert: string, i: number) => (
99 <div key={i} className="px-2 py-1.5 rounded border border-[#FF9500] bg-[#FF9500]/10 text-[#FF9500] text-[9px] font-mono leading-tight shadow-[0_0_8px_rgba(255,149,0,0.15)]">
100 {alert}
101 </div>
102 ))}
103 </div>
104 )}
105
106 {/* Ticker List */}
107 <div className="space-y-0.5 overflow-y-auto styled-scrollbar mt-2">
108 {markets[activeSection] && Object.entries(markets[activeSection]).map(([name, d]) => (
109 <Ticker key={name} name={name} data={d} />
110 ))}
111 {(!markets[activeSection] || Object.keys(markets[activeSection]).length === 0) && (
112 <div className="text-center py-3 text-[10px] font-mono text-[var(--text-muted)]">Loading {activeSection}...</div>
113 )}
114 </div>
115 </motion.div>
116 )}
117 </AnimatePresence>
118 </motion.div>
119 );
120}