"use client" import { cx } from "class-variance-authority" import { useSearchParams } from "next/navigation" import { type PropsWithChildren, useEffect, useRef } from "react" import { Button as ButtonRAC } from "react-aria-components" import { useIntl } from "react-intl" import { isBookingCodeRate } from "@scandic-hotels/booking-flow/components/SelectRate/RoomsContainer/RateSummary/utils" import { formatPrice } from "@scandic-hotels/common/utils/numberFormatting" import { Button } from "@scandic-hotels/design-system/Button" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Typography } from "@scandic-hotels/design-system/Typography" import { useEnterDetailsStore } from "@/stores/enter-details" import { formId } from "@/components/HotelReservation/EnterDetails/Payment/PaymentClient" import styles from "./bottomSheet.module.css" interface SummaryBottomSheetProps extends PropsWithChildren<{ isMember: boolean }> {} export default function SummaryBottomSheet({ children, isMember, }: SummaryBottomSheetProps) { const intl = useIntl() const scrollY = useRef(0) const searchParams = useSearchParams() const errorCode = searchParams.get("errorCode") const { isSummaryOpen, toggleSummaryOpen, totalPrice, isSubmitting, rooms } = useEnterDetailsStore((state) => ({ isSummaryOpen: state.isSummaryOpen, toggleSummaryOpen: state.actions.toggleSummaryOpen, totalPrice: state.totalPrice, isSubmitting: state.isSubmitting, rooms: state.rooms, })) useEffect(() => { if (isSummaryOpen) { scrollY.current = window.scrollY document.body.style.position = "fixed" document.body.style.top = `-${scrollY.current}px` } else { document.body.style.position = "" document.body.style.top = "" if (!errorCode) { window.scrollTo({ top: scrollY.current, left: 0, behavior: "instant", }) } } return () => { document.body.style.position = "" document.body.style.top = "" } }, [isSummaryOpen, errorCode]) const containsBookingCodeRate = rooms.find( (r) => r && isBookingCodeRate(r.room.roomRate) ) const showDiscounted = containsBookingCodeRate || isMember return (
{children}
{intl.formatMessage({ defaultMessage: "Total price", })} {formatPrice( intl, totalPrice.local.price, totalPrice.local.currency, totalPrice.local.additionalPrice, totalPrice.local.additionalPriceCurrency )} {showDiscounted && totalPrice.local.regularPrice ? ( {formatPrice( intl, totalPrice.local.regularPrice, totalPrice.local.currency )} ) : null} {intl.formatMessage({ defaultMessage: "See details", })}
) }