import type { Metadata } from "next";
import ExamsListContent from "@/components/pages/exams-list/content";
import { SiteFooter } from "@/components/site-footer";
import { cachedDecideLocale } from "@/lib/server-locale";
import { cachedGetExams } from "@/lib/api/exams";
import { assertIsPathLocale, getLocaleFromLangString } from "@/lib/locale";
import { getAlternateUrls } from "@/lib/seo";
import { t } from "@/locales";

export default async function ExamsListPage(props: {
  params: Promise<{ lang?: string }>;
}) {
  const params = await props.params;

  assertIsPathLocale(params.lang);

  const locale = await cachedDecideLocale(params.lang);
  const exams = await cachedGetExams(locale);

  return (
    <>
      <main className="mx-auto max-w-(--breakpoint-xl) p-4 md:p-6 lg:p-8 min-h-content">
        <ExamsListContent exams={exams} />
      </main>
      <SiteFooter locale={locale} />
    </>
  );
}

export async function generateMetadata(props: {
  params: Promise<{ lang?: string }>;
}): Promise<Metadata> {
  const params = await props.params;
  const locale = getLocaleFromLangString(params.lang);

  return {
    title: `${t(locale, "exams.title")} | ${t(locale, "home.seo.title")}`,
    description: t(locale, "exams.description"),
    keywords: `${t(locale, "exams.title")}, ${t(locale, "home.seo.keywords")}`,
    openGraph: {
      title: `${t(locale, "exams.title")} | ${t(locale, "home.seo.title")}`,
      description: t(locale, "exams.description"),
      tags: t(locale, "home.seo.keywords"),
    },
    alternates: getAlternateUrls(locale, "/exams"),
  };
}

export { generateStaticParams } from "@/components/pages/localed-pages";
