import {
  getPageSettingsBookingCode,
  isBookingWidgetHidden,
} from "../../../trpc/memoizedRequests"
import { FloatingBookingWidgetClient } from "./FloatingBookingWidgetClient"

import type { BookingWidgetProps } from ".."

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

  if (isHidden) {
    return null
  }

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

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