import NavigationWrapper from "@/components/navigation/NavigationWrapper";
import HeroSection from "@/components/layout/HeroSection";
import EventsSection from "@/components/events/EventsSection";
import { eventService } from "@/services/events/event.service";
import { getBackgroundImage } from "@/lib/preferences";

export const dynamic = "force-dynamic";

export default async function Home() {
  // Paralléliser les appels DB
  const [events, backgroundImage] = await Promise.all([
    eventService.getUpcomingEvents(3),
    getBackgroundImage("home", "/got-2.jpg"),
  ]);

  // Convert Date objects to strings for serialization
  const serializedEvents = events.map((event) => ({
    ...event,
    date: event.date.toISOString(),
  }));

  return (
    <main className="min-h-screen relative" style={{ backgroundColor: "var(--background)" }}>
      <NavigationWrapper />
      <HeroSection backgroundImage={backgroundImage} />
      <EventsSection events={serializedEvents} />
    </main>
  );
}
