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 { BookingConfirmationSchema } from "@/types/trpc/routers/booking/confirmation" export function mapRoomState( booking: BookingConfirmationSchema, 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 formattedTotalCost = formatPrice( intl, booking.totalPrice, booking.currencyCode ) if (booking.roomPoints) { formattedTotalCost = formatPrice( intl, booking.roomPoints, CurrencyEnum.POINTS, booking.totalPrice, booking.currencyCode ) } return { adults: booking.adults, bedDescription: room.bedType.description, breakfast, breakfastIncluded, children: booking.childrenAges.length, childrenAges: booking.childrenAges, childBedPreferences: booking.childBedPreferences, confirmationNumber: booking.confirmationNumber, currencyCode: booking.currencyCode, formattedTotalCost, 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, } }