"use client" import { useEffect, useState } from "react" import { ChevronDown } from "react-feather" import { useIntl } from "react-intl" import { dt } from "@/lib/dt" import { useDetailsStore } from "@/stores/details" import { ArrowRightIcon } from "@/components/Icons" import Button from "@/components/TempDesignSystem/Button" import Divider from "@/components/TempDesignSystem/Divider" import Link from "@/components/TempDesignSystem/Link" import Popover from "@/components/TempDesignSystem/Popover" import Body from "@/components/TempDesignSystem/Text/Body" import Caption from "@/components/TempDesignSystem/Text/Caption" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import useLang from "@/hooks/useLang" import styles from "./summary.module.css" import type { BedTypeSchema } from "@/types/components/hotelReservation/enterDetails/bedType" import type { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast" import type { SummaryProps } from "@/types/components/hotelReservation/enterDetails/summary" import type { DetailsState } from "@/types/stores/details" function storeSelector(state: DetailsState) { return { fromDate: state.data.booking.fromDate, toDate: state.data.booking.toDate, bedType: state.data.bedType, breakfast: state.data.breakfast, toggleSummaryOpen: state.actions.toggleSummaryOpen, setTotalPrice: state.actions.setTotalPrice, totalPrice: state.totalPrice, } } export default function Summary({ showMemberPrice, room }: SummaryProps) { const [chosenBed, setChosenBed] = useState() const [chosenBreakfast, setChosenBreakfast] = useState< BreakfastPackage | false >() const intl = useIntl() const lang = useLang() const { bedType, breakfast, fromDate, setTotalPrice, toDate, toggleSummaryOpen, totalPrice, } = useDetailsStore(storeSelector) const diff = dt(toDate).diff(fromDate, "days") const nights = intl.formatMessage( { id: "booking.nights" }, { totalNights: diff } ) let color: "uiTextHighContrast" | "red" = "uiTextHighContrast" if (showMemberPrice) { color = "red" } const additionalPackageCost = room.packages?.reduce( (acc, curr) => { acc.local = acc.local + parseInt(curr.localPrice.totalPrice) acc.euro = acc.euro + parseInt(curr.requestedPrice.totalPrice) return acc }, { local: 0, euro: 0 } ) || { local: 0, euro: 0 } const roomsPriceLocal = room.localPrice.price + additionalPackageCost.local const roomsPriceEuro = room.euroPrice ? room.euroPrice.price + additionalPackageCost.euro : undefined useEffect(() => { setChosenBed(bedType) if (breakfast || breakfast === false) { setChosenBreakfast(breakfast) if (breakfast === false) { setTotalPrice({ local: { price: roomsPriceLocal, currency: room.localPrice.currency, }, euro: room.euroPrice && roomsPriceEuro ? { price: roomsPriceEuro, currency: room.euroPrice.currency, } : undefined, }) } else { setTotalPrice({ local: { price: roomsPriceLocal + parseInt(breakfast.localPrice.totalPrice), currency: room.localPrice.currency, }, euro: room.euroPrice && roomsPriceEuro ? { price: roomsPriceEuro + parseInt(breakfast.requestedPrice.totalPrice), currency: room.euroPrice.currency, } : undefined, }) } } }, [ bedType, breakfast, roomsPriceLocal, room.localPrice.currency, room.euroPrice, roomsPriceEuro, setTotalPrice, ]) return (
{intl.formatMessage({ id: "Summary" })} {dt(fromDate).locale(lang).format("ddd, D MMM")} {dt(toDate).locale(lang).format("ddd, D MMM")} ({nights})
{room.roomType} {intl.formatMessage( { id: "{amount} {currency}" }, { amount: intl.formatNumber(room.localPrice.price), currency: room.localPrice.currency, } )}
{intl.formatMessage( { id: "booking.adults" }, { totalAdults: room.adults } )} {room.children?.length ? ( {intl.formatMessage( { id: "booking.children" }, { totalChildren: room.children.length } )} ) : null} {room.cancellationText} {intl.formatMessage({ id: "Rate details" })} } >
{room.packages ? room.packages.map((roomPackage) => (
{roomPackage.description}
{intl.formatMessage( { id: "{amount} {currency}" }, { amount: roomPackage.localPrice.price, currency: roomPackage.localPrice.currency, } )}
)) : null} {chosenBed ? (
{chosenBed.description} {intl.formatMessage({ id: "Based on availability" })}
{intl.formatMessage( { id: "{amount} {currency}" }, { amount: "0", currency: room.localPrice.currency } )}
) : null} {chosenBreakfast === false ? (
{intl.formatMessage({ id: "No breakfast" })} {intl.formatMessage( { id: "{amount} {currency}" }, { amount: "0", currency: room.localPrice.currency } )}
) : chosenBreakfast?.code ? (
{intl.formatMessage({ id: "Breakfast buffet" })} {intl.formatMessage( { id: "{amount} {currency}" }, { amount: chosenBreakfast.localPrice.totalPrice, currency: chosenBreakfast.localPrice.currency, } )}
) : null}
{intl.formatMessage( { id: "Total price (incl VAT)" }, { b: (str) => {str} } )} {intl.formatMessage({ id: "Price details" })}
{intl.formatMessage( { id: "{amount} {currency}" }, { amount: intl.formatNumber(totalPrice.local.price), currency: totalPrice.local.currency, } )} {totalPrice.euro && ( {intl.formatMessage({ id: "Approx." })}{" "} {intl.formatMessage( { id: "{amount} {currency}" }, { amount: intl.formatNumber(totalPrice.euro.price), currency: totalPrice.euro.currency, } )} )}
) }