import { env } from "@/env/server"
import { getDestinationCityPage } from "@/lib/trpc/memoizedRequests"

import { BookingWidget } from "@/components/BookingWidget"
import { parseBookingWidgetSearchParams } from "@/utils/url"

import type { NextSearchParams, PageArgs } from "@/types/params"

export default async function BookingWidgetDestinationCityPage(
  props: PageArgs<{}, NextSearchParams>
) {
  const searchParams = await props.searchParams
  if (env.NEW_SITE_LIVE_STATUS === "NOT_LIVE") {
    return null
  }

  const { bookingCode } = searchParams
  const pageData = await getDestinationCityPage()

  const bookingWidgetSearchParams = {
    bookingCode: bookingCode ?? "",
    city: pageData?.city.name ?? "",
  }

  const booking = parseBookingWidgetSearchParams(bookingWidgetSearchParams)

  return <BookingWidget booking={booking} />
}
