"use client" import { useIntl } from "react-intl" import { formatPrice } from "@/utils/numberFormatting" import BoldRow from "./Row/Bold" import RegularRow from "./Row/Regular" import Tbody from "./Tbody" import type { Child } from "@scandic-hotels/trpc/types/child" import type { BreakfastPackage } from "@/types/components/hotelReservation/breakfast" interface BreakfastProps { adults: number breakfast: Omit | false | undefined | null breakfastChildren: Omit | null | undefined breakfastIncluded: boolean childrenInRoom: Child[] | undefined currency: string nights: number } export default function Breakfast({ adults, breakfast, breakfastChildren, breakfastIncluded, childrenInRoom = [], currency, nights, }: BreakfastProps) { const intl = useIntl() const breakfastBuffet = intl.formatMessage({ defaultMessage: "Breakfast buffet", }) const adultsMsg = intl.formatMessage( { defaultMessage: "Breakfast ({totalAdults, plural, one {# adult} other {# adults}}) x {totalBreakfasts}", }, { totalAdults: adults, totalBreakfasts: nights } ) let kidsMsg = "" if (childrenInRoom?.length) { kidsMsg = intl.formatMessage( { defaultMessage: "Breakfast ({totalChildren, plural, one {# child} other {# children}}) x {totalBreakfasts}", }, { totalChildren: childrenInRoom.length, totalBreakfasts: nights, } ) } if (breakfastIncluded) { const included = intl.formatMessage({ defaultMessage: "Included" }) return ( {childrenInRoom?.length ? ( ) : null} ) } if (breakfast) { const adultPricePerNight = breakfast.localPrice.price * adults const breakfastAdultsPricePerNight = formatPrice( intl, adultPricePerNight, breakfast.localPrice.currency ) const { payingChildren, freeChildren } = childrenInRoom.reduce( (total, child) => { if (child.age >= 4) { total.payingChildren = total.payingChildren + 1 } else { total.freeChildren = total.freeChildren + 1 } return total }, { payingChildren: 0, freeChildren: 0 } ) const childrenPrice = breakfastChildren?.localPrice.price || 0 const childrenPricePerNight = childrenPrice * payingChildren const childCurrency = breakfastChildren?.localPrice.currency ?? breakfast.localPrice.currency const breakfastChildrenPricePerNight = formatPrice( intl, childrenPricePerNight, childCurrency ) const totalAdultsPrice = adultPricePerNight * nights const totalChildrenPrice = childrenPricePerNight * nights const breakfastTotalPrice = formatPrice( intl, totalAdultsPrice + totalChildrenPrice, breakfast.localPrice.currency ) const freeChildrenMsg = intl.formatMessage( { defaultMessage: "Breakfast ({totalChildren, plural, one {# child} other {# children}}) x {totalBreakfasts}", }, { totalChildren: freeChildren, totalBreakfasts: nights, } ) return ( {breakfastChildren ? ( ) : null} {breakfastChildren && freeChildren ? ( ) : null} {childrenInRoom?.length && !breakfastChildren ? ( ) : null} ) } if (breakfast === false) { const noBreakfast = intl.formatMessage({ defaultMessage: "No breakfast", }) return ( ) } return null }