import { getTranslations, setRequestLocale } from "next-intl/server";
import { AuthShell } from "@/components/auth/AuthCard";
import { LoginForm } from "@/components/auth/LoginForm";

export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }) {
  const { locale } = await params;
  const t = await getTranslations({ locale, namespace: "auth" });
  return { title: t("loginTitle") };
}

export default async function LoginPage({
  params,
  searchParams,
}: {
  params: Promise<{ locale: string }>;
  searchParams: Promise<{ next?: string }>;
}) {
  const { locale } = await params;
  const { next } = await searchParams;
  setRequestLocale(locale);
  const t = await getTranslations({ locale, namespace: "auth" });

  return (
    <AuthShell>
      <LoginForm
        locale={locale}
        next={next}
        titles={{
          login: t("loginTitle"),
          twoFactor: t("twoFactorTitle"),
          passwordChange: t("passwordChangeTitle"),
        }}
      />
    </AuthShell>
  );
}
