import { RateTypeEnum } from "@scandic-hotels/trpc/enums/rateType" import { formatPrice } from "@/utils/numberFormatting" import type { Product } from "@scandic-hotels/trpc/types/roomAvailability" import type { IntlShape } from "react-intl" import type { RoomRate } from "@/types/components/hotelReservation/enterDetails/details" import type { Price } from "@/types/components/hotelReservation/price" export 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 } export function isBookingCodeRate(product: Product) { if ( "corporateCheque" in product || "redemption" in product || "voucher" in product ) { return true } else { if (product.public) { return product.public.rateType !== RateTypeEnum.Regular } if (product.member) { return product.member.rateType !== RateTypeEnum.Regular } return false } } export function getNonDiscountedRate( intl: IntlShape, isMemberRate: boolean, rate: Price ) { if (isMemberRate) { return rate.local.price ? formatPrice(intl, rate.local.price, rate.local.currency) : null } else { return rate.local.regularPrice ? formatPrice(intl, rate.local.regularPrice, rate.local.currency) : null } }