import { Suspense } from 'react'
import BookClient from './BookClient'
import { getPublicSiteDictionary } from '@/lib/i18n'
import { getPublicSiteLanguage } from '@/lib/i18n.server'
import { DEFAULT_COMPANY_SLUG, siteFetchOrDefault } from '@/lib/api'
import type { PublicSitePageSections } from '@rentaldrivego/types'
import { resolvePageSectionsConfig } from '@/lib/pageSections'

export const dynamic = 'force-dynamic'

interface BrandResponse {
  brand: {
    menuConfig?: {
      pageSections?: Partial<PublicSitePageSections> | null
    } | null
  } | null
}

export default async function BookPage() {
  const language = getPublicSiteLanguage()
  const dict = getPublicSiteDictionary(language)
  const brand = await siteFetchOrDefault<BrandResponse | null>(`/site/${DEFAULT_COMPANY_SLUG}/brand`, null)
  const pageSections = resolvePageSectionsConfig(brand?.brand?.menuConfig)

  return (
    <main className="min-h-screen bg-slate-50 py-10">
      <div className="shell max-w-3xl">
        {pageSections.booking.content ? (
          <Suspense fallback={<div className="card p-8 text-sm text-slate-500">{dict.booking.loadingForm}</div>}>
            <BookClient language={language} />
          </Suspense>
        ) : null}
      </div>
    </main>
  )
}
