import EventManagement from "@/components/admin/EventManagement";
import { Card } from "@/components/ui";
import { eventService } from "@/services/events/event.service";

export const dynamic = "force-dynamic";

export default async function AdminEventsPage() {
  const events = await eventService.getEventsWithStatus();

  // Transformer les données pour la sérialisation
  const serializedEvents = events.map((event) => ({
    id: event.id,
    date: event.date.toISOString(),
    name: event.name,
    description: event.description,
    type: event.type,
    status: event.status,
    room: event.room,
    time: event.time,
    maxPlaces: event.maxPlaces,
    createdAt: event.createdAt.toISOString(),
    updatedAt: event.updatedAt.toISOString(),
    registrationsCount: event.registrationsCount,
  }));

  return (
    <Card variant="dark" className="p-6">
      <h2 className="text-2xl font-gaming font-bold mb-6 text-pixel-gold">
        Gestion des Événements
      </h2>
      <EventManagement initialEvents={serializedEvents} />
    </Card>
  );
}
