"use client" import { useEffect, useRef, useState } from "react" import { useIntl } from "react-intl" import { useRatesStore } from "@/stores/select-rate" import Button from "@/components/TempDesignSystem/Button" import Caption from "@/components/TempDesignSystem/Text/Caption" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import { formatPrice } from "@/utils/numberFormatting" import Summary from "./Summary" import styles from "./mobileSummary.module.css" import type { MobileSummaryProps } from "@/types/components/hotelReservation/selectRate/rateSummary" export default function MobileSummary({ isAllRoomsSelected, isUserLoggedIn, totalPriceToShow, }: MobileSummaryProps) { const intl = useIntl() const scrollY = useRef(0) const [isSummaryOpen, setIsSummaryOpen] = useState(false) const { booking, bookingRooms, rateDefinitions, rateSummary, vat } = useRatesStore((state) => ({ booking: state.booking, bookingRooms: state.booking.rooms, rateDefinitions: state.roomsAvailability?.rateDefinitions, rateSummary: state.rateSummary, vat: state.vat, })) function toggleSummaryOpen() { setIsSummaryOpen(!isSummaryOpen) } useEffect(() => { 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 = "" } }, [isSummaryOpen]) if (!rateDefinitions) { return null } const rooms = rateSummary.map((room, index) => ({ adults: bookingRooms[index].adults, childrenInRoom: bookingRooms[index].childrenInRoom ?? undefined, roomType: room.roomType, roomPrice: { perNight: { local: { price: room.public.localPrice.pricePerNight, currency: room.public.localPrice.currency, }, requested: undefined, }, perStay: { local: { price: room.public.localPrice.pricePerStay, currency: room.public.localPrice.currency, }, requested: undefined, }, currency: room.public.localPrice.currency, }, roomRate: { ...room.public, memberRate: room.member, publicRate: room.public, }, rateDetails: rateDefinitions.find( (rate) => rate.rateCode === room.public.rateCode )?.generalTerms, cancellationText: rateDefinitions.find((rate) => rate.rateCode === room.public.rateCode) ?.cancellationText ?? "", })) return (