"use client"; import { Card, CardContent } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Users, UserCheck, Crown, Zap } from "lucide-react"; import type { AdminUser } from "./types"; import { PLAN_LABELS } from "./types"; interface UserStatsProps { users: AdminUser[]; total: number; isLoading?: boolean; } export function UserStats({ users, total, isLoading }: UserStatsProps) { const activeUsers = users.filter((u) => u.subscription_status === "active").length; const proUsers = users.filter((u) => u.plan === "pro" || u.plan === "business" || u.plan === "enterprise").length; const freeUsers = users.filter((u) => u.plan === "free" || u.plan === "starter").length; const planDistribution = users.reduce( (acc, user) => { acc[user.plan] = (acc[user.plan] || 0) + 1; return acc; }, {} as Record ); if (isLoading) { return (
{[1, 2, 3, 4].map((i) => (
))}
); } return (
Total Users {total}
Active This Month {activeUsers}
Pro Users {proUsers}
Free Users {freeUsers}
{Object.entries(planDistribution).length > 0 && (
Distribution: {Object.entries(planDistribution).map(([plan, count]) => ( {PLAN_LABELS[plan as keyof typeof PLAN_LABELS] || plan}: {count} ))}
)}
); }