import { Footer } from "@/components/site/Footer";
import { GallerySection } from "@/components/site/GallerySection";
import { ReviewsSection } from "@/components/site/ReviewsSection";
import { ScheduleSection } from "@/components/site/ScheduleSection";
import { Hero } from "@/components/site/Hero";
import { HeroIntro } from "@/components/site/HeroIntro";
import { MenuSection } from "@/components/site/MenuSection";
import { SiteHeader } from "@/components/site/SiteHeader";
import { prisma } from "@/lib/prisma";
import { getCustomWaffleConfig } from "@/lib/custom-waffle-content";
import { getGoogleReviews } from "@/lib/google-reviews";
import { getPublicSiteContent } from "@/lib/site-content";
import { getPublicTruckEvents } from "@/lib/truck-event";
import { getPublicTruckRecurrences } from "@/lib/truck-recurrence";
import { waffleIngredientInclude } from "@/lib/waffle-ingredients";

/** Page mise en cache (ISR) ; invalidation via `revalidatePath("/")` après modifs admin. */
export const revalidate = 60;

export default async function Home() {
  const [
    waffles,
    ingredientCatalog,
    galleryImages,
    site,
    customWaffle,
    truckEvents,
    truckRecurrences,
    googleReviews,
  ] = await Promise.all([
    prisma.waffle.findMany({ include: waffleIngredientInclude }),
    prisma.ingredient.findMany({
      orderBy: { name: "asc" },
      select: { id: true, name: true, price: true, imageUrl: true },
    }),
    prisma.galleryImage.findMany({
      orderBy: [{ sortOrder: "asc" }, { createdAt: "asc" }],
    }),
    getPublicSiteContent(),
    getCustomWaffleConfig(),
    getPublicTruckEvents(),
    getPublicTruckRecurrences(),
    getGoogleReviews(),
  ]);

  return (
    <>
      <SiteHeader logoUrl={site.logoUrl} />
      <main>
        <Hero
          eyebrow={site.heroEyebrow}
          title={site.heroTitle}
          subtitle={site.heroSubtitle}
          backgroundImageUrl={site.heroBackgroundImageUrl}
          textOverImage={site.heroTextOverImage}
        />
        {!site.heroTextOverImage ? (
          <HeroIntro
            eyebrow={site.heroEyebrow}
            title={site.heroTitle}
            subtitle={site.heroSubtitle}
          />
        ) : null}
        <MenuSection
          waffles={waffles}
          intro={site.menuIntro}
          ingredientCatalog={ingredientCatalog}
          customWaffle={customWaffle}
        />
        <ScheduleSection
          events={truckEvents}
          recurrences={truckRecurrences}
          intro={site.scheduleIntro}
        />
        <GallerySection images={galleryImages} intro={site.galleryIntro} />
        {googleReviews ? <ReviewsSection data={googleReviews} /> : null}
      </main>
      <Footer hours={site.hours} />
    </>
  );
}
