import { headers } from 'next/headers';
import { detectUserLanguage, parseAcceptLanguage } from '@/lib/i18n/detect-user-language';
import { loadTranslations } from '@/lib/i18n/load-translations';
import { LanguageProvider } from '@/lib/i18n/LanguageProvider';
import { AuthShell } from '@/components/auth-shell';

export default async function AuthLayout({
  children,
}: Readonly<{
  children: React.ReactNode;
}>) {
  const headersList = await headers();
  const browserLang = parseAcceptLanguage(headersList.get('accept-language'));
  const initialLanguage = await detectUserLanguage(browserLang);
  const initialTranslations = await loadTranslations(initialLanguage);

  return (
    <LanguageProvider initialLanguage={initialLanguage} initialTranslations={initialTranslations}>
      <AuthShell>{children}</AuthShell>
    </LanguageProvider>
  );
}
