Elffuss BraidHub

kikocis/osiris public

09d1cb3093e4 · 5.5 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,
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 [activeSection, setActiveSection] = useState('stocks');
41 const markets = data.markets || {};
42
43 return (
44 <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">
45 <button onClick={() => setExpanded(!expanded)} className="flex items-center justify-between w-full mb-2">
46 <div className="flex items-center gap-2">
47 <BarChart3 className="w-3.5 h-3.5 text-[var(--gold-primary)]" />
48 <span className="hud-text text-[12px] text-[var(--text-primary)]">MARKETS & INTEL</span>
49 <span className="gotham-tag gotham-tag--low" style={{ fontSize: '7px', padding: '1px 4px' }}>LIVE</span>
50 </div>
51 <div className="flex items-center gap-2">
52 <div className="w-1.5 h-1.5 rounded-full bg-[var(--alert-green)] animate-osiris-pulse" />
53 {expanded ? <ChevronUp className="w-3 h-3 text-[var(--text-muted)]" /> : <ChevronDown className="w-3 h-3 text-[var(--text-muted)]" />}
54 </div>
55 </button>
56
57 <AnimatePresence>
58 {expanded && (
59 <motion.div initial={{ height: 0, opacity: 0 }} animate={{ height: 'auto', opacity: 1 }} exit={{ height: 0, opacity: 0 }} transition={{ duration: 0.2 }}>
60 {/* Space Weather Banner */}
61 {spaceWeather && (
62 <div className="mb-2 p-2 rounded-lg border" style={{ borderColor: `${spaceWeather.storm_color}33`, background: `${spaceWeather.storm_color}08` }}>
63 <div className="flex items-center justify-between">
64 <div className="flex items-center gap-1.5">
65 <Zap className="w-3 h-3" style={{ color: spaceWeather.storm_color }} />
66 <span className="text-[10px] font-mono tracking-widest text-[var(--text-muted)]">SPACE WEATHER</span>
67 </div>
68 <span className="text-[10px] font-mono font-bold" style={{ color: spaceWeather.storm_color }}>
69 Kp {spaceWeather.kp_index} — {spaceWeather.storm_level}
70 </span>
71 </div>
72 {spaceWeather.solar_flares?.length > 0 && (
73 <div className="mt-1 text-[8px] font-mono text-[var(--text-muted)]">
74 Latest flare: {spaceWeather.solar_flares[0].class}
75 </div>
76 )}
77 </div>
78 )}
79
80 {/* Section Tabs — icons instead of emojis */}
81 <div className="flex gap-0.5 mb-2 overflow-x-auto">
82 {SECTIONS.map(s => {
83 const Icon = s.icon;
84 return (
85 <button key={s.key} onClick={() => setActiveSection(s.key)}
86 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'}`}>
87 <Icon className="w-3 h-3" />
88 {s.label}
89 </button>
90 );
91 })}
92 </div>
93
94 {/* Ticker List */}
95 <div className="space-y-0.5 max-h-[200px] overflow-y-auto styled-scrollbar">
96 {markets[activeSection] && Object.entries(markets[activeSection]).map(([name, d]) => (
97 <Ticker key={name} name={name} data={d} />
98 ))}
99 {(!markets[activeSection] || Object.keys(markets[activeSection]).length === 0) && (
100 <div className="text-center py-3 text-[10px] font-mono text-[var(--text-muted)]">Loading {activeSection}...</div>
101 )}
102 </div>
103 </motion.div>
104 )}
105 </AnimatePresence>
106 </motion.div>
107 );
108}