"use client" import { cx } from "class-variance-authority" import { useEffect, useRef, useState } 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 { useSelectRateContext } from "../../../../../contexts/SelectRate/SelectRateContext" import { useIsLoggedIn } from "../../../../../hooks/useIsLoggedIn" import { isBookingCodeRate } from "../utils" import SummaryContent from "./Content" import styles from "./mobileSummary.module.css" export function MobileSummary() { const intl = useIntl() const scrollY = useRef(0) const [isSummaryOpen, setIsSummaryOpen] = useState( undefined ) const isUserLoggedIn = useIsLoggedIn() const { selectedRates } = useSelectRateContext() function toggleSummaryOpen() { setIsSummaryOpen(!isSummaryOpen) } useEffect(() => { if (isSummaryOpen === undefined) { return } if (isSummaryOpen) { scrollY.current = window.scrollY document.body.style.position = "fixed" document.body.style.top = `-${scrollY.current}px` document.body.style.width = "100%" } else { document.body.style.position = "" document.body.style.top = "" document.body.style.width = "" window.scrollTo({ top: scrollY.current, left: 0, behavior: "instant", }) } return () => { document.body.style.position = "" document.body.style.top = "" document.body.style.width = "" } }, [isSummaryOpen]) const containsBookingCodeRate = selectedRates.rates.find( (r) => r && isBookingCodeRate(r) ) const showDiscounted = containsBookingCodeRate || isUserLoggedIn if (!selectedRates.totalPrice) { return null } return (
{intl.formatMessage({ id: "common.totalPrice", defaultMessage: "Total price", })} {formatPrice( intl, selectedRates.totalPrice.local.price, selectedRates.totalPrice.local.currency, selectedRates.totalPrice.local.additionalPrice, selectedRates.totalPrice.local.additionalPriceCurrency )} {showDiscounted && selectedRates.totalPrice.local?.regularPrice ? (

{formatPrice( intl, selectedRates.totalPrice.local?.regularPrice, selectedRates.totalPrice.local.currency )}

) : null} {intl.formatMessage({ id: "booking.seeDetails", defaultMessage: "See details", })}
) }