import { notFound } from 'next/navigation'
import { setRequestLocale } from 'next-intl/server'
import { routing } from '@/src/i18n/routing'
import { ReactNode } from 'react'

type Props = {
  children: ReactNode
  breadcrumbs: ReactNode
  params: Promise<{ locale: string }>
}

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

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

  if (!routing.locales.includes(locale as any)) {
    notFound()
  }

  setRequestLocale(locale)

  return (
    <>
      {breadcrumbs}
      <main>{children}</main>
    </>
  )
}
