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.HIDE_FOR_NEXT_RELEASE) {
    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} />
}
