Elffuss BraidHub

kikocis/osiris public

master · 7.4 KiBRawPermalink
1'use client';
2
3import { useState } from 'react';
4import { motion, AnimatePresence } from 'framer-motion';
5import { Newspaper, ChevronDown, ChevronUp, ExternalLink, MapPin, Zap } from 'lucide-react';
6
7/* ═══════════════════════════════════════════════════════════════
8 OSIRIS — Intelligence Feed
9 SIGINT-style news aggregation with risk scoring
10 ═══════════════════════════════════════════════════════════════ */
11
12interface IntelFeedProps {
13 data: any;
14 onLocate?: (lat: number, lng: number) => void;
15}
16
17function getRiskClass(score: number): string {
18 if (score >= 8) return 'risk-critical';
19 if (score >= 6) return 'risk-high';
20 if (score >= 4) return 'risk-medium';
21 return 'risk-low';
22}
23
24function getRiskLabel(score: number): string {
25 if (score >= 8) return 'CRITICAL';
26 if (score >= 6) return 'HIGH';
27 if (score >= 4) return 'ELEVATED';
28 return 'LOW';
29}
30
31function timeAgo(dateStr: string): string {
32 try {
33 const date = new Date(dateStr);
34 const diff = Date.now() - date.getTime();
35 const mins = Math.floor(diff / 60000);
36 if (mins < 60) return `${mins}m ago`;
37 const hrs = Math.floor(mins / 60);
38 if (hrs < 24) return `${hrs}h ago`;
39 return `${Math.floor(hrs / 24)}d ago`;
40 } catch {
41 return '';
42 }
43}
44
45export default function IntelFeed({ data, onLocate }: IntelFeedProps) {
46 const [expanded, setExpanded] = useState(true);
47 const [selectedIdx, setSelectedIdx] = useState<number | null>(null);
48 const news = data.news || [];
49
50 return (
51 <motion.div
52 initial={{ opacity: 0, x: 20 }}
53 animate={{ opacity: 1, x: 0 }}
54 transition={{ delay: 0.6, duration: 0.6 }}
55 className="glass-panel flex flex-col overflow-hidden pointer-events-auto"
56 >
57 {/* Header */}
58 <button
59 onClick={() => setExpanded(!expanded)}
60 className="flex items-center justify-between px-4 py-3 hover:bg-[var(--hover-accent)] transition-colors"
61 >
62 <div className="flex items-center gap-2">
63 <Newspaper className="w-3.5 h-3.5 text-[var(--gold-primary)]" />
64 <span className="hud-text text-[12px] text-[var(--text-primary)]">SIGINT FEED</span>
65 <span className="gotham-tag gotham-tag--info" style={{ fontSize: '8px', padding: '1px 5px' }}>{news.length}</span>
66 {news.some((n: any) => n.risk_score >= 8) && (
67 <span className="gotham-tag gotham-tag--critical" style={{ fontSize: '7px', padding: '1px 4px' }}>ALERTS</span>
68 )}
69 </div>
70 <div className="flex items-center gap-2">
71 <div className="w-1.5 h-1.5 rounded-full bg-[var(--alert-green)] animate-osiris-pulse" />
72 {expanded ? <ChevronUp className="w-3 h-3 text-[var(--text-muted)]" /> : <ChevronDown className="w-3 h-3 text-[var(--text-muted)]" />}
73 </div>
74 </button>
75
76 {/* News Items */}
77 <AnimatePresence>
78 {expanded && (
79 <motion.div
80 initial={{ height: 0 }}
81 animate={{ height: 'auto' }}
82 exit={{ height: 0 }}
83 className="overflow-hidden"
84 >
85 <div className="max-h-[400px] overflow-y-auto styled-scrollbar divide-y divide-[var(--border-secondary)]">
86 {news.length === 0 ? (
87 <div className="px-4 py-6 text-center">
88 <span className="text-[11px] font-mono text-[var(--text-muted)] tracking-widest">
89 AWAITING INTELLIGENCE...
90 </span>
91 </div>
92 ) : (
93 news.slice(0, 25).map((item: any, i: number) => (
94 <div
95 key={i}
96 role="button"
97 tabIndex={0}
98 className="px-4 py-2.5 hover:bg-[var(--hover-accent)] transition-colors cursor-pointer"
99 onClick={() => { if (item.link) window.open(item.link, '_blank', 'noopener,noreferrer'); else setSelectedIdx(selectedIdx === i ? null : i); }}
100 onKeyDown={(e) => { if (e.key === 'Enter' && item.link) window.open(item.link, '_blank', 'noopener,noreferrer'); }}
101 >
102 {/* Top row: risk badge + source + time */}
103 <div className="flex items-center gap-2 mb-1">
104 <span className={`text-[9px] font-mono font-bold tracking-widest ${getRiskClass(item.risk_score)}`}>
105 {getRiskLabel(item.risk_score)}
106 </span>
107 <span className="text-[8px] font-mono text-[var(--text-muted)] bg-[var(--bg-tertiary)] px-1.5 py-0.5 rounded">
108 {item.source}
109 </span>
110 {item.coords && (
111 <button
112 onClick={(e) => {
113 e.stopPropagation();
114 onLocate?.(item.coords[0], item.coords[1]);
115 }}
116 className="text-[var(--text-muted)] hover:text-[var(--cyan-primary)] transition-colors"
117 >
118 <MapPin className="w-2.5 h-2.5" />
119 </button>
120 )}
121 <span className="text-[8px] font-mono text-[var(--text-muted)] ml-auto">
122 {timeAgo(item.published)}
123 </span>
124 </div>
125
126 {/* Title */}
127 <h4 className="text-[11px] text-[var(--text-primary)] leading-tight line-clamp-2">
128 {item.title}
129 </h4>
130
131 {/* Machine Assessment (if critical) */}
132 {item.machine_assessment && (
133 <div className="mt-1.5 flex items-start gap-1.5 bg-red-950/20 border border-red-900/20 rounded px-2 py-1">
134 <Zap className="w-2.5 h-2.5 text-red-400 flex-shrink-0 mt-0.5" />
135 <span className="text-[9px] font-mono text-red-400/80 leading-relaxed">
136 {item.machine_assessment}
137 </span>
138 </div>
139 )}
140
141 {/* Expanded details */}
142 <AnimatePresence>
143 {selectedIdx === i && (
144 <motion.div
145 initial={{ height: 0, opacity: 0 }}
146 animate={{ height: 'auto', opacity: 1 }}
147 exit={{ height: 0, opacity: 0 }}
148 className="mt-2 overflow-hidden"
149 >
150 <a
151 href={item.link}
152 target="_blank"
153 rel="noopener noreferrer"
154 className="flex items-center gap-1 text-[10px] font-mono text-[var(--cyan-primary)] hover:underline"
155 onClick={(e) => e.stopPropagation()}
156 >
157 <ExternalLink className="w-2.5 h-2.5" />
158 OPEN SOURCE
159 </a>
160 </motion.div>
161 )}
162 </AnimatePresence>
163 </div>
164 ))
165 )}
166 </div>
167 </motion.div>
168 )}
169 </AnimatePresence>
170 </motion.div>
171 );
172}