"use client" import { Fragment } from "react" import { Button as ButtonRAC } from "react-aria-components" import { useIntl } from "react-intl" import { longDateFormat } from "@scandic-hotels/common/constants/dateFormats" import { dt } from "@scandic-hotels/common/dt" import { formatPrice } from "@scandic-hotels/common/utils/numberFormatting" import Body from "@scandic-hotels/design-system/Body" import { Button } from "@scandic-hotels/design-system/Button" import Caption from "@scandic-hotels/design-system/Caption" import { Divider } from "@scandic-hotels/design-system/Divider" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import Subtitle from "@scandic-hotels/design-system/Subtitle" import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum" import { useRatesStore } from "@/stores/select-rate" import PriceDetailsModal from "@/components/HotelReservation/PriceDetailsModal" import SignupPromoDesktop from "@/components/HotelReservation/SignupPromo/Desktop" import Modal from "@/components/Modal" import useLang from "@/hooks/useLang" import { mapToPrice } from "./mapToPrice" import { isBookingCodeRate } from "./utils" import styles from "./summary.module.css" import type { RoomRate } from "@/types/components/hotelReservation/enterDetails/details" import type { SelectRateSummaryProps } from "@/types/components/hotelReservation/summary" export default function Summary({ booking, rooms, totalPrice, isMember, vat, toggleSummaryOpen, }: SelectRateSummaryProps) { const { rateSummary, defaultCurrency } = useRatesStore((state) => ({ rateSummary: state.rateSummary, defaultCurrency: state.defaultCurrency, })) const intl = useIntl() const lang = useLang() const diff = dt(booking.toDate).diff(booking.fromDate, "days") const nights = intl.formatMessage( { defaultMessage: "{totalNights, plural, one {# night} other {# nights}}", }, { totalNights: diff } ) function getMemberPrice(roomRate: RoomRate) { if ("member" in roomRate && roomRate.member) { return { amount: roomRate.member.localPrice.pricePerStay, currency: roomRate.member.localPrice.currency, pricePerNight: roomRate.member.localPrice.pricePerNight, } } return null } const memberPrice = rooms.length === 1 && rooms[0] ? getMemberPrice(rooms[0].roomRate) : null const containsBookingCodeRate = rooms.find( (r) => r && isBookingCodeRate(r.roomRate) ) const showDiscounted = containsBookingCodeRate || isMember const priceDetailsRooms = mapToPrice(rateSummary, booking.rooms, isMember) return (
{intl.formatMessage({ defaultMessage: "Booking summary", })} {dt(booking.fromDate).locale(lang).format(longDateFormat[lang])} {/* eslint-disable formatjs/no-literal-string-in-jsx */} {dt(booking.toDate).locale(lang).format(longDateFormat[lang])} ( {nights}){/* eslint-enable formatjs/no-literal-string-in-jsx */}
{rooms.map((room, idx) => { if (!room) { return null } const roomNumber = idx + 1 const adults = room.adults const childrenInRoom = room.childrenInRoom const childrenBeds = childrenInRoom?.reduce( (acc, value) => { const bedType = Number(value.bed) if (bedType === ChildBedMapEnum.IN_ADULTS_BED) { return acc } const count = acc.get(bedType) ?? 0 acc.set(bedType, count + 1) return acc }, new Map([ [ChildBedMapEnum.IN_CRIB, 0], [ChildBedMapEnum.IN_EXTRA_BED, 0], ]) ) const childBedCrib = childrenBeds?.get(ChildBedMapEnum.IN_CRIB) const childBedExtraBed = childrenBeds?.get(ChildBedMapEnum.IN_EXTRA_BED) const memberPrice = getMemberPrice(room.roomRate) const showMemberPrice = !!(isMember && memberPrice && roomNumber === 1) const showDiscounted = isBookingCodeRate(room.roomRate) || showMemberPrice const adultsMsg = intl.formatMessage( { defaultMessage: "{totalAdults, plural, one {# adult} other {# adults}}", }, { totalAdults: adults } ) const guestsParts = [adultsMsg] if (childrenInRoom?.length) { const childrenMsg = intl.formatMessage( { defaultMessage: "{totalChildren, plural, one {# child} other {# children}}", }, { totalChildren: childrenInRoom.length } ) guestsParts.push(childrenMsg) } const roomPackages = room.packages const zeroPrice = formatPrice(intl, 0, defaultCurrency) return (
{rooms.length > 1 ? ( {intl.formatMessage( { defaultMessage: "Room {roomIndex}", }, { roomIndex: roomNumber, } )} ) : null}
{room.roomType} {formatPrice( intl, room.roomPrice.perStay.local.price, room.roomPrice.perStay.local.currency, room.roomPrice.perStay.local.additionalPrice, room.roomPrice.perStay.local.additionalPriceCurrency )}
{guestsParts.join(", ")} {room.cancellationText} {intl.formatMessage({ defaultMessage: "Rate details", })} } title={room.cancellationText} >
{room.rateDetails?.map((info) => ( {info} ))}
{childBedCrib ? (
{intl.formatMessage( { defaultMessage: "Crib (child) × {count}", }, { count: childBedCrib } )} {intl.formatMessage({ defaultMessage: "Subject to availability", })}
{zeroPrice}
) : null} {childBedExtraBed ? (
{intl.formatMessage( { defaultMessage: "Extra bed (child) × {count}", }, { count: childBedExtraBed, } )}
{zeroPrice}
) : null} {roomPackages?.map((pkg) => (
{pkg.description}
{formatPrice( intl, pkg.localPrice.price, pkg.localPrice.currency )}
))}
) })}
{intl.formatMessage( { defaultMessage: "Total price (incl VAT)", }, { b: (str) => {str} } )}
{formatPrice( intl, totalPrice.local.price, totalPrice.local.currency, totalPrice.local.additionalPrice, totalPrice.local.additionalPriceCurrency )} {booking.bookingCode && totalPrice.local.regularPrice && ( {formatPrice( intl, totalPrice.local.regularPrice, totalPrice.local.currency )} )} {totalPrice.requested && ( {intl.formatMessage( { defaultMessage: "Approx. {value}", }, { value: formatPrice( intl, totalPrice.requested.price, totalPrice.requested.currency, totalPrice.requested.additionalPrice, totalPrice.requested.additionalPriceCurrency ), } )} )}
{!isMember && memberPrice ? ( ) : null}
) }