"use client"; import { Activity, AlertTriangle, AudioWaveform, ChevronRight, Hash, MessageSquare, Mic, Shield, ShieldAlert, ShieldCheck, Users, Zap, } from "lucide-react"; import Link from "next/link"; import { useEffect } from "react"; import { useAmbient } from "@/components/ambient/ambient-context"; import { AreaActivity, RadialGauge } from "@/components/charts"; import { GlassPanel } from "@/components/primitives"; import { ErrorState, MetricTile, PageTransition, SectionHeader, SkeletonHero, SkeletonMetricRow, SkeletonPanel, } from "@/components/shared"; import { useActivity, useStats, useTopReactions } from "@/hooks"; import { useStaggerReveal } from "@/hooks/use-gsap-animation"; import { formatNumber } from "@/lib/format"; import type { DashboardStats } from "@/lib/types"; function deriveSignal(stats?: DashboardStats) { if (!stats) return { tone: "signal" as const, label: "NOMINAL", state: "STABLE" }; const total = stats.total_flagged + stats.total_clean || 1; const ratio = stats.total_flagged / total; if (stats.moderation_overview.error > 0) return { tone: "vermilion" as const, label: "FAULT", state: "MOD_ERR" }; if (ratio > 0.25) return { tone: "vermilion" as const, label: "ELEVATED", state: "HIGH_RISK", }; if (ratio > 0.1) return { tone: "amber" as const, label: "WATCH", state: "ADVISORY" }; return { tone: "signal" as const, label: "NOMINAL", state: "OPTIMAL" }; } export function DashboardView({ initialStats, initialActivity, }: { initialStats?: DashboardStats; initialActivity?: Awaited>["data"]; }) { const { data: stats, isLoading, error, mutate: mutateStats, } = useStats(initialStats); const { data: activity } = useActivity(14, initialActivity); const { data: reactions } = useTopReactions(); const ambient = useAmbient(); const hudRef = useStaggerReveal(".linear-tile", { stagger: 0.035, y: 8, dependencies: [stats], }); useEffect(() => { const s = deriveSignal(stats); ambient.set( s.tone, 0.3 + Math.min(0.5, (stats?.today_flagged ?? 0) / 50), s.label, ); }, [stats, ambient]); if (error && !stats) return void mutateStats()} />; if (!stats && isLoading) return (
); if (!stats) return ( void mutateStats()} /> ); const s = stats; const total = s.total_flagged + s.total_clean || 1; const cleanRatio = s.total_clean / total; const mod = s.moderation_overview; const hasModQueue = mod.pending > 0 || mod.processing > 0 || mod.error > 0; return (
{/* Tactical HUD Header Bar */}

Telemetry Overview · Node 01

SIGNAL: {deriveSignal(stats).label} {hasModQueue && ( {mod.pending + mod.processing + mod.error} IN QUEUE )}
{/* Primary Metric Deck — 6 tiles */}
} /> } /> 0 ? "vermilion" : "neutral"} icon={} /> } /> } /> 0 ? `${mod.error} errors` : "Processing pipeline"} tone={ mod.error > 0 ? "vermilion" : mod.pending > 0 ? "amber" : "neutral" } icon={} />
{/* Moderation Queue Status Bar */} {hasModQueue && (
Pipeline Status {mod.pending > 0 && ( {mod.pending} PENDING )} {mod.processing > 0 && ( {mod.processing} PROCESSING )} {mod.error > 0 && ( {mod.error} ERROR )}
)} {/* Dynamic Activity Area & Telemetry Gauges */}
0.85 ? "signal" : "amber"} size={140} />
CLEAN
{formatNumber(s.total_clean)}
FLAGGED
{formatNumber(s.total_flagged)}
WARNED
{formatNumber(s.total_warned)}
{/* Top Channels + Engagement Row */}
{/* Top Channels Ranking */} {s.top_channels && s.top_channels.length > 0 && ( View All } />
{s.top_channels.slice(0, 6).map((ch, i) => { const maxCount = s.top_channels[0]?.message_count || 1; const pct = Math.max( 4, Math.round((ch.message_count / maxCount) * 100), ); return (
{String(i + 1).padStart(2, "0")} {ch.channel_name ?? ch.channel_id.slice(0, 14)}
{formatNumber(ch.message_count)}
); })}
)} {/* Top Reacted Messages */} {reactions && reactions.length > 0 && (
{reactions.slice(0, 4).map((r) => (
{r.content || "[Media/Attachment]"} {r.username && ( @{r.username} {r.channel_name && ` in #${r.channel_name}`} )}
{formatNumber(r.reaction_count)} {r.top_emojis && r.top_emojis.length > 0 && (
{r.top_emojis.map((e) => ( {e.emoji} ))}
)}
))}
)}
{/* Quick Navigation */}
Live Moderation Queue Active Voice Stages Flagged Content Analysis Voice Recording Archive
); }