import UserManagement from "@/components/admin/UserManagement";
import { Card } from "@/components/ui";
import { userService } from "@/services/users/user.service";

export const dynamic = "force-dynamic";

export default async function AdminUsersPage() {
  const users = await userService.getAllUsers({
    orderBy: {
      score: "desc",
    },
    select: {
      id: true,
      username: true,
      email: true,
      role: true,
      score: true,
      level: true,
      hp: true,
      maxHp: true,
      xp: true,
      maxXp: true,
      avatar: true,
      createdAt: true,
    },
  });

  // Sérialiser les dates pour le client
  const serializedUsers = users.map((user) => ({
    ...user,
    createdAt: user.createdAt.toISOString(),
  }));

  return (
    <Card variant="dark" className="p-6">
      <h2 className="text-2xl font-gaming font-bold mb-6 text-pixel-gold">
        Gestion des Utilisateurs
      </h2>
      <UserManagement initialUsers={serializedUsers} />
    </Card>
  );
}
