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

export const metadata: Metadata = {
  title: 'Reset password',
  robots: { index: false, follow: false },
};

/**
 * One route, two jobs.
 *
 * With a token it sets a new password; without one it asks for a reset
 * link. Same page because a reader who follows an expired link needs to
 * request a fresh one from exactly here, and bouncing them to a
 * different URL to do it is friction at the worst moment.
 */
export default async function ResetPage({
  params,
  searchParams,
}: {
  params: Promise<{ lang: string }>;
  searchParams: Promise<{ t?: string }>;
}) {
  const { lang } = await params;
  if (!isLocale(lang)) notFound();

  const { t } = await searchParams;
  const dict = getDictionary(lang);

  return (
    <main id="main" className="page auth-page">
      {t ? (
        <ResetForm token={t} locale={lang} dict={dict} />
      ) : (
        <ForgotForm locale={lang} dict={dict} />
      )}
    </main>
  );
}
