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

import BookingWidget, { preload } from "@/components/BookingWidget"

import { PageArgs } from "@/types/params"

export default async function BookingWidgetPage({
  searchParams,
}: PageArgs<{}, URLSearchParams>) {
  if (!env.ENABLE_BOOKING_WIDGET_HOTELRESERVATION_PATH) {
    return null
  }

  preload()

  // Get the booking widget show/hide status based on page specific settings
  const bookingWidgetToggle =
    await serverClient().contentstack.bookingwidget.toggle.get()

  if (bookingWidgetToggle.hideBookingWidget) {
    return null
  }

  return <BookingWidget searchParams={searchParams} />
}
