import { useMemo } from "react"; import { Bar, BarChart, Cell, Pie, PieChart, ResponsiveContainer, Tooltip, XAxis, YAxis, } from "recharts"; import { useApp } from "../context/AppContext"; import { useTheme } from "../context/ThemeContext"; import { useI18n } from "../i18n/I18nContext"; function cssVar(name: string, fallback: string): string { if (typeof window === "undefined") return fallback; return ( getComputedStyle(document.documentElement).getPropertyValue(name).trim() || fallback ); } export function HubPage() { const { hubHistory, threshold } = useApp(); const { theme } = useTheme(); const { t } = useI18n(); const colors = useMemo( () => ({ safe: cssVar("--safe", "#2f8f3e"), toxic: cssVar("--toxic", "#c2331f"), accent: cssVar("--accent", "#d83d2c"), muted: cssVar("--muted", "#6b6256"), }), [theme] ); const toxic = hubHistory.filter((h) => h.score >= threshold).length; const safe = hubHistory.length - toxic; const pieData = [ { name: t.hub.safe, value: safe || 1 }, { name: t.hub.toxic, value: toxic || 0 }, ]; const pieColors = [colors.safe, colors.toxic]; const barData = hubHistory.slice(0, 12).map((h, i) => ({ name: `#${i + 1}`, score: Math.round(h.score * 100), })); return (

{t.hub.title}

{t.hub.threshold} {threshold.toFixed(2)}
{t.hub.eventsLogged} {hubHistory.length}
{t.hub.toxicSession} {toxic}

{t.hub.safeVsToxic}

{pieData.map((_, i) => ( ))}

{t.hub.recentScores}

{t.hub.recentActions}

{hubHistory.length === 0 ? ( ) : ( hubHistory.map((h, i) => ( )) )}
{t.hub.colUser} {t.hub.colComment} {t.hub.colScore} {t.hub.colAction}
{t.hub.emptyHistory}
{h.user} {h.snippet} {(h.score * 100).toFixed(0)}% {h.action}
); }