import {
  getPageSettingsBookingCode,
  isBookingWidgetHidden,
} from "@/lib/trpc/memoizedRequests"

import { FloatingBookingWidgetClient } from "./FloatingBookingWidgetClient"

import type { BookingWidgetProps } from "@/types/components/bookingWidget"

export async function FloatingBookingWidget({
  booking,
}: Omit<BookingWidgetProps, "type">) {
  const isHidden = await isBookingWidgetHidden()

  if (isHidden) {
    return null
  }

  let pageSettingsBookingCodePromise: Promise<string> | null = null
  if (!booking.bookingCode) {
    pageSettingsBookingCodePromise = getPageSettingsBookingCode()
  }

  return (
    <FloatingBookingWidgetClient
      data={booking}
      pageSettingsBookingCodePromise={pageSettingsBookingCodePromise}
    />
  )
}
