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

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' ? 'الحساب' : 'Account',
    // Never indexed: it renders one person's settings and has no search
    // value at all.
    robots: { index: false, follow: false },
  };
}

/**
 * Account settings.
 *
 * Client-rendered, unlike the rest of the site. The session is an
 * httpOnly cookie the browser sends automatically, and this page shows
 * only the signed-in reader's own data — so there is nothing to
 * server-render for SEO and no benefit to doing so.
 */
export default async function AccountPage({ params }: { params: Params }) {
  const { lang } = await params;
  if (!isLocale(lang)) notFound();

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