import type { Metadata } from 'next';
import { notFound } from 'next/navigation';
import { isLocale } from '@ai-radar/shared';
import { getDictionary } from '@/lib/dictionary';
import { AuthForm } from '@/components/auth/AuthForm';

type Params = Promise<{ lang: string }>;

export async function generateMetadata({ params }: { params: Params }): Promise<Metadata> {
  const { lang } = await params;
  if (!isLocale(lang)) return {};

  return {
    title: lang === 'ar' ? 'تسجيل الدخول' : 'Sign in',
    // Deliberately not indexed: a sign-in page has no search value and
    // adds a thin page to the index.
    robots: { index: false, follow: true },
  };
}

export default async function SignInPage({ params }: { params: Params }) {
  const { lang } = await params;
  if (!isLocale(lang)) notFound();

  return (
    <main id="main" className="page auth-page">
      <AuthForm mode="signin" locale={lang} dict={getDictionary(lang)} />
    </main>
  );
}
