"use client"; import { useRouter } from "next/navigation"; import { ArrowLeft, ScanLine, Trophy, Zap, Calendar } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Avatar, AvatarFallback } from "@/components/ui/avatar"; import { Switch } from "@/components/ui/switch"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { toast } from "sonner"; import { formatDate } from "@/lib/utils"; interface UserDetailProps { user: { id: string; name: string; email: string; role: string; xp: number; level: number; banned: boolean; bannedReason: string | null; createdAt: Date; scans: { id: string; confidence: number; createdAt: Date; disease: { name: string; severity: string } | null; }[]; _count: { scans: number }; }; } const SEVERITY_STYLES: Record = { HIGH: "bg-wine/10 text-[#FB7185] border-wine/20", MEDIUM: "bg-gold/10 text-gold border-gold/20", LOW: "bg-[#60A5FA]/10 text-[#60A5FA] border-[#60A5FA]/20", }; export default function UserDetailClient({ user }: UserDetailProps) { const router = useRouter(); async function handleUpdate(data: Record) { try { const res = await fetch(`/api/users/${user.id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify(data), }); if (!res.ok) throw new Error(); toast.success("Utilisateur mis a jour"); router.refresh(); } catch { toast.error("Erreur lors de la mise a jour"); } } const STAT_ITEMS = [ { label: "Scans", value: user._count.scans, icon: ScanLine, color: "text-vine" }, { label: "XP", value: user.xp, icon: Zap, color: "text-gold" }, { label: "Niveau", value: user.level, icon: Trophy, color: "text-[#A78BFA]" }, { label: "Inscrit", value: formatDate(user.createdAt, "MMM yyyy"), icon: Calendar, color: "text-[#60A5FA]" }, ]; return (

Utilisateur

{/* Profile card */}
{user.name.charAt(0).toUpperCase()}

{user.name}

{user.role} {user.banned && ( Banni )}

{user.email}

Inscrit le {formatDate(user.createdAt)}

{/* Stats */}
{STAT_ITEMS.map((stat) => (

{stat.value}

{stat.label}

))}
{/* Admin actions */}

Actions admin

Role

Modifier le role de l'utilisateur

Bannir

Empecher l'acces a l'application

handleUpdate({ banned })} />
{/* Scan history */}

Historique des scans

{user.scans.length === 0 ? (

Aucun scan

) : ( user.scans.map((scan) => (

{scan.disease?.name || "Non identifie"}

{formatDate(scan.createdAt)}

{scan.disease?.severity && ( {scan.disease.severity} )} {Math.round(scan.confidence * 100)}%
)) )}
); }