"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 { 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 "../../../Payment/PaymentClient" import { isDiscounted } from "../../UI/utils" import styles from "./bottomSheet.module.css" type SummaryBottomSheetProps = PropsWithChildren<{ isUserLoggedIn: boolean }> export default function SummaryBottomSheet({ children, isUserLoggedIn, }: 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 showDiscounted = isUserLoggedIn || rooms.some((room) => isDiscounted(room.room)) return (
{children}
{intl.formatMessage({ id: "common.totalPrice", 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({ id: "booking.seeDetails", defaultMessage: "See details", })}
) }