import { useIntl } from "react-intl" import { dt } from "@scandic-hotels/common/dt" import DiscountIcon from "@scandic-hotels/design-system/Icons/DiscountIcon" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { Typography } from "@scandic-hotels/design-system/Typography" import { RoomPackageCodeEnum } from "@scandic-hotels/trpc/enums/roomFilter" import { changeOrCancelDateFormat } from "@/constants/dateFormats" import GuestDetails from "@/components/HotelReservation/MyStay/GuestDetails" import PriceType from "@/components/HotelReservation/MyStay/PriceType" import { hasModifiableRate } from "@/components/HotelReservation/MyStay/utils" import { sumPackages } from "@/components/HotelReservation/utils" import ImageGallery from "@/components/ImageGallery" import Accordion from "@/components/TempDesignSystem/Accordion" import AccordionItem from "@/components/TempDesignSystem/Accordion/AccordionItem" import IconChip from "@/components/TempDesignSystem/IconChip" import SidePeekSelfControlled from "@/components/TempDesignSystem/SidePeekSelfControlled" import useLang from "@/hooks/useLang" import { mapApiImagesToGalleryImages } from "@/utils/imageGallery" import { formatPrice } from "@/utils/numberFormatting" import RoomDetails from "./RoomDetails" import styles from "./bookedRoomSidePeek.module.css" import type { Child } from "@scandic-hotels/trpc/types/child" import type { Room as HotelRoom } from "@scandic-hotels/trpc/types/hotel" import type { Packages } from "@scandic-hotels/trpc/types/packages" import type { BreakfastPackage } from "@/types/components/hotelReservation/breakfast" import type { BedTypeSchema } from "@/types/components/hotelReservation/enterDetails/bedType" import type { PriceTypeEnum } from "@/types/components/hotelReservation/myStay/myStay" import type { BookingConfirmationSchema } from "@/types/trpc/routers/booking/confirmation" import type { SafeUser } from "@/types/user" type PartialHotelRoom = Pick< HotelRoom, "descriptions" | "images" | "name" | "roomFacilities" | "roomTypes" > export type Room = Pick< BookingConfirmationSchema, | "adults" | "bookingCode" | "cancellationNumber" | "checkInDate" | "cheques" | "confirmationNumber" | "refId" | "currencyCode" | "guest" | "rateDefinition" | "totalPoints" | "totalPrice" | "vouchers" > & { bedType: BedTypeSchema breakfast: Omit | false | undefined childrenInRoom: Child[] isCancelled: boolean packages: Packages | null priceType: PriceTypeEnum roomName: string roomNumber: number terms: string | null } interface RoomDetailsSidePeekProps { hotelRoom: PartialHotelRoom | null room: Room user: SafeUser } export default function BookedRoomSidePeek({ hotelRoom, room, user, }: RoomDetailsSidePeekProps) { const intl = useIntl() const lang = useLang() const { adults, bedType, bookingCode, breakfast, cancellationNumber, checkInDate, cheques, childrenInRoom, confirmationNumber, refId, currencyCode, guest, isCancelled, roomName, packages, priceType, rateDefinition, roomNumber, totalPoints, terms, totalPrice, vouchers, } = room let totalRoomPrice = totalPrice // API returns negative values for totalPrice // on voucher bookings (╯°□°)╯︵ ┻━┻ if (vouchers && totalRoomPrice < 0) { const pkgsSum = sumPackages(packages) totalRoomPrice = pkgsSum.price } const fromDate = dt(checkInDate).locale(lang) const galleryImages = hotelRoom ? mapApiImagesToGalleryImages(hotelRoom.images) : null const adultsMsg = intl.formatMessage( { defaultMessage: "{adults, plural, one {# adult} other {# adults}}", }, { adults: adults, } ) const childrenMsg = intl.formatMessage( { defaultMessage: "{children, plural, one {# child} other {# children}}", }, { children: childrenInRoom.length, } ) const adultsOnlyMsg = adultsMsg const adultsAndChildrenMsg = [adultsMsg, childrenMsg].join(", ") const formattedTotalPrice = formatPrice(intl, totalPrice, currencyCode) let breakfastPrice = intl.formatMessage({ defaultMessage: "No breakfast", }) if (rateDefinition.breakfastIncluded) { breakfastPrice = intl.formatMessage({ defaultMessage: "Included", }) } else if (breakfast) { breakfastPrice = formatPrice( intl, breakfast.localPrice.totalPrice, breakfast.localPrice.currency ) } const hotelRoomName = hotelRoom?.name || roomName return (
{isCancelled ? ( } > {intl.formatMessage({ defaultMessage: "Cancelled", })} ) : (
{intl.formatMessage( { defaultMessage: "Room {roomIndex}", }, { roomIndex: roomNumber } )}
)}
{isCancelled ? ( {intl.formatMessage({ defaultMessage: "Cancellation no", })} {/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} {":"} ) : ( {intl.formatMessage({ defaultMessage: "Booking number", })} {/* eslint-disable-next-line formatjs/no-literal-string-in-jsx */} {":"} )} {isCancelled ? ( {cancellationNumber} ) : ( {confirmationNumber} )}
{galleryImages ? ( ) : null}

{intl.formatMessage({ defaultMessage: "Guests", })}

{childrenInRoom.length > 0 ? adultsAndChildrenMsg : adultsOnlyMsg}

{intl.formatMessage({ defaultMessage: "Terms", })}

{terms}

{hasModifiableRate(rateDefinition.cancellationRule) && (

{intl.formatMessage({ defaultMessage: "Modify By", })}

{intl.formatMessage( { defaultMessage: "Until {time}, {date}", }, { time: "18:00", date: fromDate.format(changeOrCancelDateFormat[lang]), } )}

)}

{intl.formatMessage({ defaultMessage: "Breakfast", })}

{breakfastPrice}

{packages?.some((item) => Object.values(RoomPackageCodeEnum).includes( item.code as RoomPackageCodeEnum ) ) && (

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

{packages ?.filter((item) => Object.values(RoomPackageCodeEnum).includes( item.code as RoomPackageCodeEnum ) ) .map((item) => item.description) .join(", ")}

)}

{intl.formatMessage({ defaultMessage: "Bed preference", })}

{bedType?.description}

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

{bookingCode && ( } > {intl.formatMessage( { defaultMessage: "Booking code: {value}", }, { value: bookingCode, strong: (text) => ( {text} ), } )} )}
{hotelRoom ? ( ) : null}
) }