import { motion } from "framer-motion";
import {
AlertCircle,
BarChart3,
MessageSquare,
Mic,
RefreshCw,
ShieldAlert,
UserCheck,
Users,
} from "lucide-react";
import { cardItem, cardStagger } from "../../../shared/hooks/useFramerStagger";
import { cn } from "../../../shared/lib/utils";
import {
Card,
CardContent,
CardHeader,
CardTitle,
Skeleton,
} from "../../../shared/ui";
import { useDashboardStats } from "../hooks/useDashboard";
import { useUIState } from "../../../shared/hooks/useUIState";
export function DashboardStatsContent() {
const { stats, loading, error, refetch } = useDashboardStats();
const { patchUIState } = useUIState();
if (loading) {
return ;
}
if (error) {
return (
{error}
);
}
if (!stats) {
return (
);
}
const cards = [
{
title: "Total Messages",
value: stats.total_messages.toLocaleString(),
icon: MessageSquare,
color: "text-primary",
bg: "bg-primary/10",
},
{
title: "Today's Messages",
value: stats.today_messages.toLocaleString(),
icon: MessageSquare,
color: "text-emerald-500",
bg: "bg-emerald-100",
},
{
title: "Total Users",
value: stats.total_users.toLocaleString(),
icon: Users,
color: "text-blue-500",
bg: "bg-blue-100",
},
{
title: "Active Users (24h)",
value: stats.active_users_24h.toLocaleString(),
icon: UserCheck,
color: "text-violet-500",
bg: "bg-violet-100",
},
{
title: "Flagged",
value: stats.total_flagged.toLocaleString(),
icon: ShieldAlert,
color: "text-destructive",
bg: "bg-destructive/10",
},
{
title: "Clean",
value: stats.total_clean.toLocaleString(),
icon: ShieldAlert,
color: "text-emerald-600",
bg: "bg-emerald-100",
},
{
title: "Voice Recordings",
value: stats.total_voice_recordings.toLocaleString(),
icon: Mic,
color: "text-cyan-500",
bg: "bg-cyan-100",
onClick: () => patchUIState({ activeTab: "live" }),
},
{
title: "AI Profiles",
value: stats.total_profiles.toLocaleString(),
icon: Users,
color: "text-amber-500",
bg: "bg-amber-100",
},
];
return (
{/* Summary cards grid */}
{cards.map((card) => (
{card.title}
{card.value}
))}
{/* Top channels */}
Top Channels
{stats.top_channels.length === 0 ? (
No channel data yet.
) : (
{stats.top_channels.map((ch, i) => (
#{ch.channel_name ?? ch.channel_id}
{ch.message_count.toLocaleString()}
))}
)}
{/* Moderation overview */}
Moderation Queue
{stats.moderation_overview.pending}
Pending
{stats.moderation_overview.processing}
Processing
{stats.moderation_overview.error}
Errors
);
}
function StatsSkeleton() {
return (
{Array.from({ length: 8 }).map((_, i) => (
))}
);
}