import type { Metadata } from "next";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { HeroSection } from "@/components/hero/Hero";
import { PageMessagesProvider } from "@/components/page-messages-provider";
import { BreakthroughSection } from "@/components/sections/breakthrough-section";
import { CallToAction } from "@/components/sections/call-to-action";
import { ContactSection } from "@/components/sections/contact-section";
import { FAQSection } from "@/components/sections/faq-section";
import { FeaturesSectionIntteligence } from "@/components/sections/full-intteligence";
import LatestBlogPosts from "@/components/sections/latest-blog-posts";
import { TechCloud } from "@/components/sections/tech-cloud";
import { Testimonials } from "@/components/sections/testimonials";
import { WhyChooseUs } from "@/components/sections/why-choose-us";
import { FAQSchema } from "@/components/ui/faq-schema";
import { getFaqConfigs } from "@/data/faq";
import { getPathname } from "@/i18n/navigation";

interface PageProps {
  params: Promise<{ locale: string }>;
}

export async function generateMetadata({
  params,
}: PageProps): Promise<Metadata> {
  const { locale } = await params;
  const t = await getTranslations({ locale, namespace: "metadata" });
  const pathname = getPathname({ locale, href: "/" });
  return {
    title: t("homeTitle"),
    description: t("homeDescription"),
    alternates: {
      canonical: pathname,
      languages: {
        fr: getPathname({ locale: "fr", href: "/" }),
        en: getPathname({ locale: "en", href: "/" }),
        "x-default": getPathname({ locale: "fr", href: "/" }),
      },
    },
  };
}

export default async function HomePage({
  params,
}: {
  params: Promise<{ locale: string }>;
}) {
  const { locale } = await params;
  setRequestLocale(locale);

  const homeFaqConfig = getFaqConfigs(locale).home;

  return (
    <PageMessagesProvider
      namespaces={[
        "hero",
        "techCloud",
        "whyChooseUs",
        "fullIntelligence",
        "breakthrough",
        "testimonials",
        "cta",
        "faq",
        "contact",
        "secondaryCta",
        "symptomsGrid",
      ]}
    >
      <FAQSchema faqs={homeFaqConfig.faqs} />
      <HeroSection />
      <TechCloud />
      <WhyChooseUs />
      <FeaturesSectionIntteligence />
      <BreakthroughSection />
      <Testimonials />
      <LatestBlogPosts locale={locale} />
      <CallToAction />
      <FAQSection {...homeFaqConfig} />
      <ContactSection />
    </PageMessagesProvider>
  );
}
