import SiteNavigation from '@/components/SiteNavigation'
import React from 'react'
import { getPayload } from 'payload'
import config from '@/payload.config'
import { Header } from '@/payload-types'

export const metadata = {
  description: 'House of Study for Temple Beth El',
  title: 'Midrashim',
}

export default async function RootLayout(props: { children: React.ReactNode }) {
  const { children } = props

  const payloadConfig = await config
  const payload = await getPayload({ config: payloadConfig })

  const headerGlobals = (await payload.findGlobal({
    slug: 'header',
  })) as Header

  const navItems =
    headerGlobals.headerLinks?.map((l) => ({
      label: l.label || '',
      href: l.href || '',
      newTab: l.newTab || false,
    })) || []

  return <SiteNavigation navItems={navItems}>{children}</SiteNavigation>
}
