import { formatPrice } from "@/utils/numberFormatting" import type { IntlShape } from "react-intl" import type { BookingConfirmationRoom } from "@/types/components/hotelReservation/bookingConfirmation/bookingConfirmation" import { BreakfastPackageEnum } from "@/types/enums/breakfast" import { CurrencyEnum } from "@/types/enums/currency" import type { BookingSchema } from "@/types/trpc/routers/booking/confirmation" export function mapRoomState( booking: BookingSchema, room: BookingConfirmationRoom, intl: IntlShape ) { const breakfast = booking.packages.find( (pkg) => pkg.code === BreakfastPackageEnum.REGULAR_BREAKFAST ) const breakfastIncluded = booking.packages.some( (pkg) => pkg.code === BreakfastPackageEnum.FREE_MEMBER_BREAKFAST ) let formattedRoomCost = formatPrice( intl, booking.roomPrice, booking.currencyCode ) if (booking.roomPoints) { formattedRoomCost = formatPrice( intl, booking.roomPoints, CurrencyEnum.POINTS, booking.totalPrice, booking.currencyCode ) } else if (booking.cheques) { formattedRoomCost = formatPrice( intl, booking.cheques, CurrencyEnum.CC, booking.totalPrice, booking.currencyCode ) } else if (booking.vouchers) { formattedRoomCost = formatPrice( intl, booking.vouchers, CurrencyEnum.Voucher ) } return { adults: booking.adults, bedDescription: room.bedType.description, bookingCode: booking.bookingCode, breakfast, breakfastIncluded, cheques: booking.cheques, childrenAges: booking.childrenAges, childBedPreferences: booking.childBedPreferences, confirmationNumber: booking.confirmationNumber, currencyCode: booking.currencyCode, formattedRoomCost, fromDate: booking.checkInDate, name: room.name, packages: booking.packages, rateDefinition: booking.rateDefinition, roomFeatures: booking.packages.filter((p) => p.type === "RoomFeature"), roomPoints: booking.roomPoints, roomPrice: booking.roomPrice, roomTypeCode: booking.roomTypeCode, toDate: booking.checkOutDate, totalPrice: booking.totalPrice, totalPriceExVat: booking.totalPriceExVat, vatAmount: booking.vatAmount, vouchers: booking.vouchers, } }