import type { Metadata } from "next";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { PageMessagesProvider } from "@/components/page-messages-provider";
import { ContactSection } from "@/components/sections/contact-section";
import { BreadcrumbSchema } from "@/components/ui/breadcrumb-schema";
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: "/contact" });
  return {
    title: t("contactTitle"),
    description: t("contactDescription"),
    alternates: {
      canonical: pathname,
      languages: {
        fr: getPathname({ locale: "fr", href: "/contact" }),
        en: getPathname({ locale: "en", href: "/contact" }),
        "x-default": getPathname({ locale: "fr", href: "/contact" }),
      },
    },
  };
}

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

  const tb = await getTranslations({ locale, namespace: "breadcrumbs" });
  const contactUrl = `https://www.elevaseo.com${locale === "fr" ? "" : `/${locale}`}/contact`;

  const contactPageJsonLd = {
    "@context": "https://schema.org",
    "@type": "ContactPage",
    name: locale === "fr" ? "Contacter ElevaSEO" : "Contact ElevaSEO",
    description:
      locale === "fr"
        ? "Discutez de votre projet headless, audit SEO ou migration avec ElevaSEO. Reponse sous 24h ouvrees."
        : "Get in touch with ElevaSEO about your headless build, SEO audit, or migration project. Response within 24 business hours.",
    url: contactUrl,
    inLanguage: locale,
    isPartOf: {
      "@type": "WebSite",
      name: "ElevaSEO",
      url: "https://www.elevaseo.com",
    },
    mainEntity: {
      "@type": "Organization",
      name: "ElevaSEO",
      url: "https://www.elevaseo.com",
      logo: "https://www.elevaseo.com/logo.webp",
      email: "bastien@elevaseo.com",
      contactPoint: [
        {
          "@type": "ContactPoint",
          contactType: "customer service",
          email: "bastien@elevaseo.com",
          url: contactUrl,
          availableLanguage: ["French", "English"],
          areaServed: ["FR", "US", "GB", "CA", "BE", "CH"],
        },
      ],
    },
  };

  return (
    <PageMessagesProvider namespaces={["contact"]}>
      <script
        dangerouslySetInnerHTML={{ __html: JSON.stringify(contactPageJsonLd) }}
        type="application/ld+json"
      />
      <BreadcrumbSchema
        items={[{ name: tb("home"), href: "/" }, { name: tb("contact") }]}
        locale={locale}
      />
      <div className="min-h-screen py-8 md:py-20">
        <ContactSection />
      </div>
    </PageMessagesProvider>
  );
}
