import { prisma } from "@/lib/prisma";
import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";

export const dynamic = "force-dynamic";

export default async function SuperAdminPage() {
  const establishments = await prisma.establishment.count();
  const users = await prisma.user.count();
  const students = await prisma.student.count();
  const nodesOnline = await prisma.node.count({ where: { status: "online" } });
  const instancesRunning = await prisma.instance.count({ where: { status: "running" } });
  const activeSubs = await prisma.subscription.count({ where: { status: "active" } });

  return (
    <div className="space-y-6">
      <h1 className="text-3xl font-bold">Super Admin — Vue globale</h1>
      <div className="grid grid-cols-1 md:grid-cols-3 lg:grid-cols-3 gap-4">
        <Card>
          <CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Établissements</CardTitle></CardHeader>
          <CardContent><div className="text-3xl font-bold">{establishments}</div></CardContent>
        </Card>
        <Card>
          <CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Utilisateurs</CardTitle></CardHeader>
          <CardContent><div className="text-3xl font-bold">{users}</div></CardContent>
        </Card>
        <Card>
          <CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Étudiants</CardTitle></CardHeader>
          <CardContent><div className="text-3xl font-bold">{students}</div></CardContent>
        </Card>
        <Card>
          <CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Nœuds en ligne</CardTitle></CardHeader>
          <CardContent><div className="text-3xl font-bold">{nodesOnline}</div></CardContent>
        </Card>
        <Card>
          <CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Instances running</CardTitle></CardHeader>
          <CardContent><div className="text-3xl font-bold">{instancesRunning}</div></CardContent>
        </Card>
        <Card>
          <CardHeader className="pb-2"><CardTitle className="text-sm font-medium text-muted-foreground">Abonnements actifs</CardTitle></CardHeader>
          <CardContent><div className="text-3xl font-bold">{activeSubs}</div></CardContent>
        </Card>
      </div>
    </div>
  );
}
