import { cx } from "class-variance-authority" import { useIntl } from "react-intl" import { Button } from "@scandic-hotels/design-system/Button" import { Divider } from "@scandic-hotels/design-system/Divider" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Typography } from "@scandic-hotels/design-system/Typography" import { ChildBedMapEnum } from "@scandic-hotels/trpc/enums/childBedMapEnum" import Modal from "@/components/Modal" import { formatPrice } from "@/utils/numberFormatting" import { getMemberPrice, getPublicPrice } from "../utils" import Breakfast from "./Breakfast" import styles from "./room.module.css" import type { CurrencyEnum } from "@scandic-hotels/common/constants/currency" import type { Room as RoomType } from "@/types/stores/enter-details" interface RoomProps { room: RoomType roomNumber: number roomCount: number isMember: boolean isSpecialRate: boolean nightsCount: number defaultCurrency: CurrencyEnum } export default function Room({ room, roomNumber, roomCount, isMember, isSpecialRate, nightsCount, defaultCurrency, }: RoomProps) { const intl = useIntl() 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 publicPrice = getPublicPrice(room.roomRate) const isFirstRoomMember = roomNumber === 1 && isMember const isOrWillBecomeMember = !!( room.guest.join || room.guest.membershipNo || isFirstRoomMember ) const showMemberPrice = !!(isOrWillBecomeMember && memberPrice) const showDiscounted = isSpecialRate || 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) } let rateDetails = room.rateDetails if (room.memberRateDetails) { if (isMember || room.guest.join) { rateDetails = room.memberRateDetails } } const guests = guestsParts.join(", ") const zeroPrice = formatPrice(intl, 0, defaultCurrency) let price = showMemberPrice ? formatPrice(intl, memberPrice.amount, memberPrice.currency) : formatPrice( intl, room.roomPrice.perStay.local.price, room.roomPrice.perStay.local.currency, room.roomPrice.perStay.local.additionalPrice, room.roomPrice.perStay.local.additionalPriceCurrency ) let currency: string = room.roomPrice.perStay.local.currency const voucherCurrency = intl.formatMessage({ defaultMessage: "Voucher" }) const isVoucher = "voucher" in room.roomRate if (isVoucher) { currency = voucherCurrency price = formatPrice( intl, room.roomPrice.perStay.local.price, voucherCurrency, room.roomPrice.perStay.local.additionalPrice, room.roomPrice.perStay.local.additionalPriceCurrency ) } return ( <>
{roomCount > 1 ? (

{intl.formatMessage( { defaultMessage: "Room {roomIndex}", }, { roomIndex: roomNumber, } )}

) : null}

{room.roomType}

{guests}

{room.cancellationText}

{price}

{showDiscounted && publicPrice ? ( {formatPrice( intl, publicPrice.amount, publicPrice.currency )} ) : null}
{rateDetails?.length ? (
{intl.formatMessage({ defaultMessage: "Rate details", })} } title={room.cancellationText} >
{rateDetails.map((info) => (

{info}

))}
) : null}
{room.roomFeatures ? room.roomFeatures.map((feature) => (

{feature.description}

{formatPrice( intl, feature.localPrice.price, feature.localPrice.currency )}
)) : null} {room.bedType ? (

{room.bedType.description}

{zeroPrice}
) : null} {childBedCrib ? (

{intl.formatMessage( { defaultMessage: "Crib (child) × {count}", }, { count: childBedCrib } )}

{intl.formatMessage({ defaultMessage: "Subject to availability", })}

{formatPrice(intl, 0, currency)}
) : null} {childBedExtraBed ? (

{intl.formatMessage( { defaultMessage: "Extra bed (child) × {count}", }, { count: childBedExtraBed, } )}

{formatPrice(intl, 0, currency)}
) : null}
) }