import { Users, Coins, TrendingUp, Gift, Loader2, AlertTriangle, CheckCircle, XCircle, Info, Clock, Wifi, Trophy, Crown, Gem, Wrench, } from "lucide-react"; import { cn } from "../lib/utils"; import { useDashboard, type DashboardStats } from "../lib/useDashboard"; function formatNumber(n: number | string): string { const num = typeof n === "string" ? parseFloat(n) : n; if (num >= 1_000_000) return `${(num / 1_000_000).toFixed(1)}M`; if (num >= 1_000) return `${(num / 1_000).toFixed(1)}K`; return num.toLocaleString(); } function formatUptime(ms: number): string { const hours = Math.floor(ms / 3_600_000); const minutes = Math.floor((ms % 3_600_000) / 60_000); if (hours >= 24) { const days = Math.floor(hours / 24); return `${days}d ${hours % 24}h`; } return `${hours}h ${minutes}m`; } function timeAgo(ts: string | Date): string { const diff = Date.now() - new Date(ts).getTime(); const mins = Math.floor(diff / 60_000); if (mins < 1) return "just now"; if (mins < 60) return `${mins}m ago`; const hours = Math.floor(mins / 60); if (hours < 24) return `${hours}h ago`; return `${Math.floor(hours / 24)}d ago`; } const eventIcons = { success: CheckCircle, error: XCircle, warn: AlertTriangle, info: Info, } as const; const eventColors = { success: "text-success", error: "text-destructive", warn: "text-warning", info: "text-info", } as const; function StatCard({ icon: Icon, label, value, sub, accent = "border-primary", }: { icon: React.ComponentType<{ className?: string }>; label: string; value: string; sub?: string; accent?: string; }) { return (
{label}
{value}
{sub &&
{sub}
}
); } function LeaderboardColumn({ title, icon: Icon, entries, valueKey, valuePrefix, }: { title: string; icon: React.ComponentType<{ className?: string }>; entries: Array<{ username: string; [k: string]: unknown }>; valueKey: string; valuePrefix?: string; }) { return (

{title}

{entries.length === 0 && (
No data
)} {entries.slice(0, 10).map((entry, i) => (
#{i + 1} {entry.username}
{valuePrefix} {formatNumber(entry[valueKey] as string | number)}
))}
); } export default function Dashboard() { const { data, loading, error } = useDashboard(); if (loading) { return (
); } if (error) { return (

{error}

); } if (!data) return null; return ; } function DashboardContent({ data }: { data: DashboardStats }) { return (
{/* Maintenance banner */} {data.maintenanceMode && (
Maintenance mode is active
)} {/* Stat cards */}
{/* Leaderboards */} {data.leaderboards && (

Leaderboards

)} {/* Recent Events */} {data.recentEvents.length > 0 && (

Recent Events

{data.recentEvents.slice(0, 20).map((event, i) => { const Icon = eventIcons[event.type]; return (
{event.icon && {event.icon}} {event.message} {timeAgo(event.timestamp)}
); })}
)} {/* Bot status footer */}
); }