import { isLocale, type Locale, publicPath } from "@/i18n/routes";
import { getDict } from "@/i18n/dictionaries";
import { LinksSection } from "@/components/links-section";
import { getDb } from "@/lib/db";
import { seedIfEmpty } from "@/lib/seed";
import { getProfile } from "@/lib/models";
import { buildMetadata } from "@/lib/metadata";

export async function generateMetadata({
  params,
}: {
  params: Promise<{ lang: string }>;
}) {
  const { lang } = await params;
  const locale: Locale = isLocale(lang) ? lang : "de";
  return buildMetadata(locale, getDict(locale).contact.title, getDict(locale).contact.lede, { path: publicPath(locale, "contact") });
}

export default async function ContactPage({
  params,
}: {
  params: Promise<{ lang: string }>;
}) {
  const { lang } = await params;
  const locale: Locale = isLocale(lang) ? lang : "de";
  const db = getDb();
  seedIfEmpty(db);
  const profile = getProfile(db, locale);
  const dict = getDict(locale);
  return (
    <>
      <div className="section-heading">
        <span className="section-heading__label">~/contact</span>
        <h1 className="section-heading__title">{dict.contact.title}</h1>
      </div>
      <p className="mb-6 max-w-2xl text-[var(--fg)]">{dict.contact.lede}</p>
      <LinksSection profile={profile} locale={locale} />
    </>
  );
}
