﻿import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { loadDictionary } from "@allai/i18n/server";
import { locales, resolveLocale } from "@/config/i18n";
import { AboutPage } from "@/features/marketing/AboutPage";
import { absoluteUrl, buildCanonical, buildLocaleAlternates, buildOpenGraph, buildTwitterCard } from "@/seo/seoUtils";

const PATH = "/about" as const;

type PageProps = {
  params: { locale: string };
};

export async function generateMetadata({ params }: PageProps): Promise<Metadata> {
  const locale = resolveLocale(params.locale);
  if (!locales.includes(locale)) {
    return { title: "About" };
  }
  const dictionary = await loadDictionary(locale);
  const title = `About ${dictionary.common.brandShort}`;
  const description =
    "Learn how AllAI empowers creative teams with AI image and video workflows, collaborative tooling, and responsible guardrails.";

  return {
    title,
    description,
    alternates: {
      canonical: buildCanonical(locale, PATH),
      languages: buildLocaleAlternates(PATH)
    },
    openGraph: buildOpenGraph({
      locale: locale,
      title,
      description,
      path: PATH
    }),
    twitter: buildTwitterCard({
      title,
      description
    })
  };
}

export default async function AboutRoute({ params }: PageProps) {
  const locale = resolveLocale(params.locale);
  if (!locales.includes(locale)) {
    notFound();
  }
  const dictionary = await loadDictionary(locale);

  const structuredData = {
    "@context": "https://schema.org",
    "@type": "Organization",
    name: dictionary.common.brandLong ?? dictionary.common.brandShort,
    url: buildCanonical(locale, PATH),
    logo: absoluteUrl("/favicon.ico"),
    sameAs: [
      "https://www.linkedin.com/company/allai-studio",
      "https://twitter.com/allai_studio"
    ]
  };

  return (
    <>
      <script
        type="application/ld+json"
        suppressHydrationWarning
        dangerouslySetInnerHTML={{ __html: JSON.stringify(structuredData) }}
      />
      <AboutPage dictionary={dictionary} />
    </>
  );
}


