import type { Metadata } from 'next';
import { getTranslations } from 'next-intl/server';
import WelcomeScreen from './WelcomeScreen';

export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }): Promise<Metadata> {
  const { locale } = await params;
  const t = await getTranslations({ locale, namespace: 'welcome' });
  const tCommon = await getTranslations({ locale, namespace: 'common' });

  // The middleware REWRITES an unauthenticated '/' to this route (never a redirect), so this is
  // the content served at both '/{locale}' and '/{locale}/welcome' — canonicalize on the former,
  // the URL a guest and every crawler actually sees.
  const canonicalPath = `/${locale}`;

  return {
    description: t('meta_description'),
    alternates: { canonical: canonicalPath },
    openGraph: {
      title: tCommon('brand'),
      description: t('meta_description'),
      type: 'website',
      locale: locale === 'fa' ? 'fa_IR' : 'en_US',
      url: canonicalPath,
    },
  };
}

export default function Page() {
  return <WelcomeScreen />;
}
