"use client"; import { useEffect, useState } from "react"; import { Users, ClipboardList, ShieldAlert, CheckCircle } from "lucide-react"; import { Header } from "@/components/layout/header"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { clientsApi, auditsApi, type Client, type Audit } from "@/lib/api"; import { getToken } from "@/lib/auth"; type Stats = { totalClients: number; totalAudits: number; auditsEnCours: number; auditsTermines: number; }; export default function DashboardPage() { const [stats, setStats] = useState({ totalClients: 0, totalAudits: 0, auditsEnCours: 0, auditsTermines: 0, }); const [recentAudits, setRecentAudits] = useState([]); const [loading, setLoading] = useState(true); useEffect(() => { const token = getToken(); if (!token) return; Promise.all([clientsApi.list(token), auditsApi.list(token)]) .then(([clients, audits]) => { setStats({ totalClients: clients.length, totalAudits: audits.length, auditsEnCours: audits.filter((a) => a.statut === "en_cours").length, auditsTermines: audits.filter((a) => a.statut === "termine").length, }); setRecentAudits(audits.slice(0, 5)); }) .finally(() => setLoading(false)); }, []); const statCards = [ { label: "Clients", value: stats.totalClients, icon: Users, color: "text-blue-600" }, { label: "Audits total", value: stats.totalAudits, icon: ClipboardList, color: "text-purple-600" }, { label: "En cours", value: stats.auditsEnCours, icon: ShieldAlert, color: "text-orange-500" }, { label: "Terminés", value: stats.auditsTermines, icon: CheckCircle, color: "text-green-600" }, ]; const statutLabels: Record = { planifie: "Planifié", en_cours: "En cours", termine: "Terminé", annule: "Annulé", }; const statutColors: Record = { planifie: "text-blue-600 bg-blue-50", en_cours: "text-orange-600 bg-orange-50", termine: "text-green-600 bg-green-50", annule: "text-gray-500 bg-gray-50", }; return (
{/* Stats cards */}
{statCards.map(({ label, value, icon: Icon, color }) => ( {label}

{loading ? : value}

))}
{/* Recent audits */} Audits récents {loading ? (

Chargement...

) : recentAudits.length === 0 ? (

Aucun audit pour le moment.

) : (
{recentAudits.map((audit) => (

{audit.nom}

{new Date(audit.createdAt).toLocaleDateString("fr-FR")}

{statutLabels[audit.statut]}
))}
)}
); }