import { BookingWidget } from "@scandic-hotels/booking-flow/BookingWidget"
import { parseBookingWidgetSearchParams } from "@scandic-hotels/booking-flow/utils/url"

import { serverClient } from "@/lib/trpc"

import { getLang } from "@/i18n/serverContext"

import type { Lang } from "@scandic-hotels/common/constants/language"

type SearchParams<S = {}> = {
  searchParams: Promise<S & { [key: string]: string }>
}

export default async function Home(props: SearchParams<{ lang: Lang }>) {
  const searchParams = await props.searchParams

  // TODO we need this import right now to ensure configureServerClient is called,
  // but we should ensure it's called in a layout instead.
  const _caller = await serverClient()
  const lang = await getLang()

  const booking = parseBookingWidgetSearchParams(searchParams)

  return (
    <div>
      <BookingWidget booking={booking} lang={lang} />
    </div>
  )
}
