"use client" import { Fragment } from "react" import { useIntl } from "react-intl" import { Typography } from "@scandic-hotels/design-system/Typography" import { dt } from "@/lib/dt" import { PriceTagIcon } from "@/components/Icons" import Body from "@/components/TempDesignSystem/Text/Body" import Caption from "@/components/TempDesignSystem/Text/Caption" import useLang from "@/hooks/useLang" import { formatPrice } from "@/utils/numberFormatting" import styles from "./priceDetailsTable.module.css" import type { Price } from "@/types/components/hotelReservation/price" import type { Room } from "@/stores/my-stay/myStayRoomDetailsStore" function Row({ label, value, bold, }: { label: string value: string bold?: boolean }) { return ( {label} {value} ) } function TableSection({ children }: React.PropsWithChildren) { return {children} } function TableSectionHeader({ title, subtitle, }: { title: string subtitle?: string }) { return ( <> {title} {subtitle && ( {subtitle} )} ) } export type RoomPriceDetails = Pick< Room, | "adults" | "bedType" | "breakfast" | "childrenInRoom" | "roomPrice" | "roomName" | "packages" | "isCancelled" > & { guest?: Room["guest"] } export interface PriceDetailsTableProps { bookingCode?: string | null fromDate: string bookedRoom: RoomPriceDetails linkedReservationRooms: RoomPriceDetails[] toDate: string totalPrice: Price vat: number } export default function PriceDetailsTable({ bookingCode, fromDate, bookedRoom, linkedReservationRooms, toDate, totalPrice, vat, }: PriceDetailsTableProps) { const intl = useIntl() const lang = useLang() const rooms = [bookedRoom, ...linkedReservationRooms].filter( (room) => !room.isCancelled ) const diff = dt(toDate).diff(fromDate, "days") const nights = intl.formatMessage( { id: "{totalNights, plural, one {# night} other {# nights}}" }, { totalNights: diff } ) const vatPercentage = vat / 100 const vatAmount = totalPrice.local.price * vatPercentage const priceExclVat = totalPrice.local.price - vatAmount const duration = ` ${dt(fromDate).locale(lang).format("ddd, D MMM")} - ${dt(toDate).locale(lang).format("ddd, D MMM")} (${nights})` return ( {rooms.map((room, idx) => { return ( {rooms.length > 1 && ( )} {room.packages ? room.packages.map((feature) => ( )) : null} {room.breakfast ? ( {room.childrenInRoom?.length ? ( ) : null} ) : null} ) })} {totalPrice.local.regularPrice && ( )} {bookingCode && totalPrice.local.regularPrice && ( )}
{intl.formatMessage( { id: "Room {roomIndex}" }, { roomIndex: idx + 1 } )}
{intl.formatMessage({ id: "Price including VAT" })} {formatPrice( intl, totalPrice.local.price, totalPrice.local.currency )}
{formatPrice( intl, totalPrice.local.regularPrice, totalPrice.local.currency )}
{bookingCode}
) }