"use client"; import { Activity, Download, Hash } from "lucide-react"; import { useMemo, useState } from "react"; import { Badge, GlassPanel } from "@/components/primitives"; import { SectionHeader } from "@/components/shared"; import { useStaggerReveal } from "@/hooks/use-gsap-animation"; import { downloadCsv } from "@/lib/csv"; import { formatRelativeTime } from "@/lib/format"; import type { ChannelCultureRow } from "@/lib/types"; function deriveSignalStrength(c: ChannelCultureRow): number { let score = 0.3; if (c.culture_summary) { score += Math.min(0.45, c.culture_summary.length / 350); } if (c.last_analyzed_at) { const ageMs = Date.now() - c.last_analyzed_at; const days = ageMs / (1000 * 60 * 60 * 24); score += Math.max(0, 0.25 - days * 0.015); } return Math.max(0.12, Math.min(1, score)); } export function ChannelCultureGlossary({ cultures, }: { cultures: ChannelCultureRow[]; }) { const [filter, setFilter] = useState(""); const ranked = useMemo(() => { return cultures .map((c) => ({ c, signal: deriveSignalStrength(c) })) .sort((a, b) => b.signal - a.signal); }, [cultures]); const filtered = useMemo(() => { if (!filter.trim()) return ranked; const q = filter.toLowerCase(); return ranked.filter( ({ c }) => c.channel_name?.toLowerCase().includes(q) || c.channel_id.toLowerCase().includes(q) || c.culture_summary?.toLowerCase().includes(q), ); }, [ranked, filter]); const containerRef = useStaggerReveal(".channel-node-card", { stagger: 0.03, y: 10, dependencies: [filtered.length, filter], }); return (
{/* Search and Quick Filters */}
setFilter(e.target.value)} className="w-full rounded-[6px] border border-hairline bg-surface-2 py-1.5 pl-9 pr-3 text-xs text-ink placeholder:text-ink-faint focus:border-signal focus:outline-none" />
{cultures.length > 0 && ( )}
{/* Channel Nodes Grid */} {filtered.length} of {cultures.length} channels } /> {filtered.length === 0 ? (
NO MATCHING CHANNEL TELEMETRY FOUND
) : (
{filtered.map(({ c, signal }) => { const pct = Math.round(signal * 100); const isHighSignal = signal > 0.65; return (
{/* Channel Card Header */}
{c.channel_name ?? c.channel_id.slice(0, 10)}
{pct}% SIGNAL
{/* Culture Summary */}
{c.culture_summary ? (

{c.culture_summary}

) : (

Awaiting AI culture profile synthesis...

)}
{/* Signal Strength Bar & Timestamp */}
INTEL RATIO {c.last_analyzed_at ? formatRelativeTime(c.last_analyzed_at) : "NEVER"}
); })}
)}
); }