import { getDictionary } from "@/content";
import { isLocale } from "@/content/types";
import { getPublishedOffers } from "@/lib/actions/offers";
import { getGalleryPhotos } from "@/lib/actions/gallery";
import { getApprovedReviews } from "@/lib/actions/reviews";
import { Hero } from "@/components/sections/Hero";
import { About } from "@/components/sections/About";
import { WhyUs } from "@/components/sections/WhyUs";
import { Destinations } from "@/components/sections/Destinations";
import { Experiences } from "@/components/sections/Experiences";
import { OffersSection } from "@/components/sections/OffersSection";
import { GallerySection } from "@/components/sections/GallerySection";
import { Services } from "@/components/sections/Services";
import { ReviewsSection } from "@/components/sections/ReviewsSection";
import { BookingForm } from "@/components/sections/BookingForm";

export default async function HomePage({
  params,
}: {
  params: Promise<{ locale: string }>;
}) {
  const { locale: rawLocale } = await params;
  const locale = isLocale(rawLocale) ? rawLocale : "en";
  const dict = getDictionary(locale);

  const [offers, photos, reviews] = await Promise.all([
    getPublishedOffers(),
    getGalleryPhotos(),
    getApprovedReviews(),
  ]);
  const heroPhoto = photos.find((p) => p.destinationSlug === "hero") ?? photos[0] ?? null;
  const aboutPhoto = photos.find((p) => p.destinationSlug === "about") ?? null;

  return (
    <>
      <Hero dict={dict} locale={locale} heroPhoto={heroPhoto} />
      <About dict={dict} photo={aboutPhoto} />
      <WhyUs dict={dict} />
      <Destinations dict={dict} locale={locale} photos={photos} />
      <Experiences dict={dict} />
      <OffersSection dict={dict} locale={locale} offers={offers} />
      <GallerySection dict={dict} locale={locale} photos={photos} />
      <Services dict={dict} />
      <ReviewsSection dict={dict} reviews={reviews} />
      <BookingForm dict={dict} locale={locale} />
    </>
  );
}
