import { redirect } from 'next/navigation';
import { I18nProvider } from '../../i18n/provider';
import { isLocale, locales, messages } from '../../i18n/messages';

export function generateStaticParams() {
  return locales.map((locale) => ({ locale }));
}

export default async function LocaleLayout({
  children,
  params,
}: {
  children: React.ReactNode;
  params: Promise<{ locale: string }>;
}) {
  const { locale } = await params;
  if (!isLocale(locale)) redirect('/fa');

  const dir = locale === 'en' ? 'ltr' : 'rtl';

  return (
    <I18nProvider locale={locale} messages={messages[locale]}>
      <div
        dir={dir}
        data-locale={locale}
        className={locale === 'fa' ? 'locale-fa locale-rtl locale-scope' : 'locale-en locale-ltr locale-scope'}
      >
        {children}
      </div>
    </I18nProvider>
  );
}
