import type { Metadata } from "next";
import { getTranslations, setRequestLocale } from "next-intl/server";
import { PageMessagesProvider } from "@/components/page-messages-provider";
import { AboutSection } from "@/components/sections/about-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: "/about" });
  return {
    title: t("aboutTitle"),
    description: t("aboutDescription"),
    alternates: {
      canonical: pathname,
      languages: {
        fr: getPathname({ locale: "fr", href: "/about" }),
        en: getPathname({ locale: "en", href: "/about" }),
        "x-default": getPathname({ locale: "fr", href: "/about" }),
      },
    },
  };
}

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

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

  const profilePageJsonLd = {
    "@context": "https://schema.org",
    "@type": "ProfilePage",
    url: aboutUrl,
    inLanguage: locale,
    dateCreated: "2024-01-01",
    dateModified: "2026-03-20",
    mainEntity: {
      "@type": "Person",
      name: "Bastien Allain",
      jobTitle:
        locale === "fr"
          ? "Fondateur & Specialiste SEO/GSO"
          : "Founder & SEO/GSO Specialist",
      description:
        locale === "fr"
          ? "Specialiste SEO technique et GSO (Generative Search Optimization). Optimisation web au niveau du code : Core Web Vitals, Next.js, WordPress, Shopify Headless."
          : "Technical SEO and GSO (Generative Search Optimization) specialist. Code-level web optimization: Core Web Vitals, Next.js, WordPress, Shopify Headless.",
      image: "https://www.elevaseo.com/authors/bastien-allain.webp",
      url: aboutUrl,
      sameAs: [
        "https://www.linkedin.com/in/bastien-allain-372392389/",
        "https://twitter.com/SeoEleva",
      ],
      worksFor: {
        "@type": "Organization",
        name: "ElevaSEO",
        url: "https://www.elevaseo.com",
      },
      knowsAbout: [
        "SEO",
        "GSO",
        "Generative Search Optimization",
        "Headless CMS",
        "Next.js",
        "Shopify Headless",
        "WordPress",
        "Core Web Vitals",
        "Web Performance",
        "CRO",
      ],
    },
  };

  return (
    <PageMessagesProvider namespaces={["about"]}>
      <script
        dangerouslySetInnerHTML={{ __html: JSON.stringify(profilePageJsonLd) }}
        type="application/ld+json"
      />
      <BreadcrumbSchema
        items={[{ name: tb("home"), href: "/" }, { name: tb("about") }]}
        locale={locale}
      />
      <AboutSection />
    </PageMessagesProvider>
  );
}
