import React from 'react'
import { notFound } from 'next/navigation'
import { isValidLocale, locales, getLocaleDirection, type Locale } from '@/lib/i18n'

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

interface LocaleLayoutProps {
  children: React.ReactNode
  params: Promise<{ locale: string }>
}

export default async function LocaleLayout({ children, params }: LocaleLayoutProps) {
  const { locale } = await params

  if (!isValidLocale(locale)) {
    notFound()
  }

  const direction = getLocaleDirection(locale as Locale)

  return (
    <html lang={locale} dir={direction}>
      <body>
        <main>{children}</main>
      </body>
    </html>
  )
}
