209 lines
5.9 KiB
TypeScript
209 lines
5.9 KiB
TypeScript
"use client"
|
|
import { useIntl } from "react-intl"
|
|
|
|
import { formatPrice } from "@scandic-hotels/common/utils/numberFormatting"
|
|
|
|
import BoldRow from "./Row/Bold"
|
|
import RegularRow from "./Row/Regular"
|
|
import Tbody from "./Tbody"
|
|
|
|
import type { BreakfastPackage } from "@scandic-hotels/trpc/routers/hotels/schemas/packages"
|
|
import type { Child } from "@scandic-hotels/trpc/types/child"
|
|
|
|
interface BreakfastProps {
|
|
adults: number
|
|
breakfast: Omit<BreakfastPackage, "requestedPrice"> | false | undefined | null
|
|
breakfastChildren: Omit<BreakfastPackage, "requestedPrice"> | null | undefined
|
|
breakfastIncluded: boolean
|
|
childrenInRoom: Child[] | undefined
|
|
currency: string
|
|
nights: number
|
|
hotelOffersBreakfast?: boolean
|
|
}
|
|
|
|
export default function Breakfast({
|
|
adults,
|
|
breakfast,
|
|
breakfastChildren,
|
|
breakfastIncluded,
|
|
childrenInRoom = [],
|
|
currency,
|
|
nights,
|
|
hotelOffersBreakfast = true,
|
|
}: BreakfastProps) {
|
|
const intl = useIntl()
|
|
|
|
const breakfastBuffet = intl.formatMessage({
|
|
id: "common.breakfastBuffet",
|
|
defaultMessage: "Breakfast buffet",
|
|
})
|
|
|
|
const adultsMsg = intl.formatMessage(
|
|
{
|
|
id: "priceDetails.breakfastAdultsDetails",
|
|
defaultMessage:
|
|
"Breakfast ({totalAdults, plural, one {# adult} other {# adults}}) x {totalBreakfasts}",
|
|
},
|
|
{ totalAdults: adults, totalBreakfasts: nights }
|
|
)
|
|
|
|
let kidsMsg = ""
|
|
if (childrenInRoom?.length) {
|
|
kidsMsg = intl.formatMessage(
|
|
{
|
|
id: "priceDetails.breakfastChildrenDetails",
|
|
defaultMessage:
|
|
"Breakfast ({totalChildren, plural, one {# child} other {# children}}) x {totalBreakfasts}",
|
|
},
|
|
{
|
|
totalChildren: childrenInRoom.length,
|
|
totalBreakfasts: nights,
|
|
}
|
|
)
|
|
}
|
|
|
|
if (breakfastIncluded) {
|
|
const included = intl.formatMessage({
|
|
id: "common.included",
|
|
defaultMessage: "Included",
|
|
})
|
|
return (
|
|
<Tbody>
|
|
<RegularRow label={adultsMsg} value={included} />
|
|
{childrenInRoom?.length ? (
|
|
<RegularRow label={kidsMsg} value={included} />
|
|
) : null}
|
|
<BoldRow
|
|
label={breakfastBuffet}
|
|
value={formatPrice(intl, 0, currency)}
|
|
/>
|
|
</Tbody>
|
|
)
|
|
}
|
|
|
|
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(
|
|
{
|
|
id: "priceDetails.breakfastChildrenDetails",
|
|
defaultMessage:
|
|
"Breakfast ({totalChildren, plural, one {# child} other {# children}}) x {totalBreakfasts}",
|
|
},
|
|
{
|
|
totalChildren: freeChildren,
|
|
totalBreakfasts: nights,
|
|
}
|
|
)
|
|
|
|
return (
|
|
<Tbody border>
|
|
<RegularRow
|
|
label={intl.formatMessage(
|
|
{
|
|
id: "priceDetails.breakfastAdultsDetails",
|
|
defaultMessage:
|
|
"Breakfast ({totalAdults, plural, one {# adult} other {# adults}}) x {totalBreakfasts}",
|
|
},
|
|
{ totalAdults: adults, totalBreakfasts: nights }
|
|
)}
|
|
value={breakfastAdultsPricePerNight}
|
|
/>
|
|
{breakfastChildren ? (
|
|
<RegularRow
|
|
label={intl.formatMessage(
|
|
{
|
|
id: "priceDetails.breakfastChildrenDetails",
|
|
defaultMessage:
|
|
"Breakfast ({totalChildren, plural, one {# child} other {# children}}) x {totalBreakfasts}",
|
|
},
|
|
{
|
|
totalChildren: payingChildren,
|
|
totalBreakfasts: nights,
|
|
}
|
|
)}
|
|
value={breakfastChildrenPricePerNight}
|
|
/>
|
|
) : null}
|
|
{breakfastChildren && freeChildren ? (
|
|
<RegularRow
|
|
label={`${freeChildrenMsg} (0-3)`}
|
|
value={formatPrice(intl, 0, breakfast.localPrice.currency)}
|
|
/>
|
|
) : null}
|
|
{childrenInRoom?.length && !breakfastChildren ? (
|
|
<RegularRow
|
|
label={intl.formatMessage(
|
|
{
|
|
id: "priceDetails.breakfastChildrenDetails",
|
|
defaultMessage:
|
|
"Breakfast ({totalChildren, plural, one {# child} other {# children}}) x {totalBreakfasts}",
|
|
},
|
|
{
|
|
totalChildren: childrenInRoom.length,
|
|
totalBreakfasts: nights,
|
|
}
|
|
)}
|
|
value={formatPrice(intl, 0, breakfast.localPrice.currency)}
|
|
/>
|
|
) : null}
|
|
<BoldRow label={breakfastBuffet} value={breakfastTotalPrice} />
|
|
</Tbody>
|
|
)
|
|
}
|
|
|
|
if (breakfast === false) {
|
|
const noBreakfast = intl.formatMessage({
|
|
id: "common.noBreakfast",
|
|
defaultMessage: "No breakfast",
|
|
})
|
|
return (
|
|
<Tbody>
|
|
<BoldRow
|
|
label={hotelOffersBreakfast ? breakfastBuffet : undefined}
|
|
value={noBreakfast}
|
|
/>
|
|
</Tbody>
|
|
)
|
|
}
|
|
|
|
return null
|
|
}
|