"use client"; import { AlertTriangle, BarChart3, CheckCircle2, Globe, Hash, Shield, TrendingUp, } from "lucide-react"; import { useEffect, useState } from "react"; import { useAmbient } from "@/components/ambient/ambient-context"; import { LiveModerationFeed } from "@/components/LiveModerationFeed"; import { ModerationHeatmap } from "@/components/ModerationHeatmap"; import { GlassPanel } from "@/components/primitives"; import { ScamDomains } from "@/components/ScamDomains"; import { ErrorState, MetricTile, PageTransition, SectionHeader, SkeletonMetricRow, SkeletonPanel, } from "@/components/shared"; import { TopChannels } from "@/components/TopChannels"; import { useHourlyModeration, useModerationActions, useModerationCoverage, useModerationStats, useModerationTrends, useTopFlaggedChannels, useTopFlaggedDomains, } from "@/hooks"; import { useStaggerReveal } from "@/hooks/use-gsap-animation"; import { formatNumber } from "@/lib/format"; import type { ModerationAction, ModerationCoverage, ModerationStats, } from "@/lib/types"; export function ModerationView({ initialStats, initialActions, initialCoverage: _initialCoverage, }: { initialStats?: ModerationStats; initialActions?: ModerationAction[]; initialCoverage?: ModerationCoverage; }) { const { data: stats, isLoading, error, mutate, } = useModerationStats(initialStats); const { data: actions } = useModerationActions( undefined, undefined, initialActions, ); const { data: hourly } = useHourlyModeration(); const { data: domains } = useTopFlaggedDomains(30); const { data: channels } = useTopFlaggedChannels(30); const { data: trends } = useModerationTrends(30); const { data: coverage } = useModerationCoverage(30); const ambient = useAmbient(); const [filterMode, setFilterMode] = useState<"all" | "flagged" | "clean">( "all", ); const containerRef = useStaggerReveal(".mod-tile", { stagger: 0.035, y: 8, dependencies: [stats], }); const executed = stats?.executed ?? 0; const failed = stats?.failed ?? 0; const total = stats?.total || 1; const failedRatio = failed / total; useEffect(() => { if (failedRatio > 0.15) ambient.set("vermilion", 0.5, "high failure rate"); else if (failedRatio > 0.05) ambient.set("amber", 0.35, "moderate issues"); else ambient.set("signal", 0.25, "moderation nominal"); }, [failedRatio, ambient]); if (error && !stats) return void mutate()} />; if (!stats && isLoading) return (
); if (!stats) return null; return (
{/* Tactical HUD Header Bar */}
0.1 ? "bg-vermilion shadow-[0_0_8px_var(--color-vermilion-glow)]" : "bg-signal shadow-[0_0_8px_var(--color-signal-glow)]" }`} />

Moderation Intelligence Console

EXECUTION: {Math.round((executed / total) * 100)}% RATE {coverage && ( <> COVERAGE: = 90 ? "bg-signal/15 text-signal border-signal/30" : "bg-amber/15 text-amber border-amber/30" }`} > {Math.round(coverage.coverage_rate)}% )}
{(["all", "flagged", "clean"] as const).map((mode) => ( ))}
{/* Primary Metric Grid */}
} /> } /> 0.05 ? "vermilion" : "neutral"} icon={} /> {coverage && ( = 90 ? "signal" : "amber"} icon={} /> )}
{/* Live Moderation Stream */}
{ if (filterMode === "flagged") return r.status === "failed"; if (filterMode === "clean") return r.status === "executed"; return true; }) ?? [] } />
{/* Heatmap Section */} {hourly && hourly.length > 0 && (
)} {/* Domains, Channels, and Trends — 3-column row */}
{/* Top Flagged Domains */} {domains && domains.length > 0 && (
)} {/* Top Flagged Channels */} {channels && channels.length > 0 && (
)} {/* Moderation Trends */} {trends && (
{/* Categories */} {trends.categories.length > 0 && (
By Category
{trends.categories.slice(0, 8).map((cat) => ( {cat.name} {cat.count} ))}
)} {/* Severities */} {trends.severities.length > 0 && (
By Severity
{trends.severities.map((sev) => { const maxSev = Math.max( ...trends.severities.map((s) => s.count), ); const pct = maxSev ? Math.round((sev.count / maxSev) * 100) : 0; const tone = sev.level === "critical" || sev.level === "high" ? "bg-vermilion" : sev.level === "medium" ? "bg-amber" : "bg-signal"; return (
{sev.level}
{sev.count}
); })}
)} {/* Action Types */} {trends.actions.length > 0 && (
By Action Type
{trends.actions.map((act) => ( {act.type.replace(/_/g, " ")} {act.count} ))}
)}
)}
{/* Coverage Progress Bar */} {coverage && (
{formatNumber(coverage.completed)}/ {formatNumber(coverage.total)} ( {Math.round(coverage.coverage_rate)}%) } />
= 90 ? "bg-signal" : coverage.coverage_rate >= 70 ? "bg-amber" : "bg-vermilion" }`} style={{ width: `${Math.min(100, coverage.coverage_rate)}%`, }} />
{formatNumber(coverage.completed)} analyzed {formatNumber(coverage.pending)} pending ·{" "} {formatNumber(coverage.failed)} failed
)}
); }