import { headers } from 'next/headers'
import { detectUserLanguage, parseAcceptLanguage } from '@/lib/i18n/detect-user-language'
import { loadTranslations } from '@/lib/i18n/load-translations'
import { PublicProviders } from '@/components/public-providers'

export default async function PublicLayout({ children }: { 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 (
    <PublicProviders initialLanguage={initialLanguage} initialTranslations={initialTranslations}>
      {children}
    </PublicProviders>
  )
}
