"use client"
import React from "react"
import { useIntl } from "react-intl"
import { dt } from "@/lib/dt"
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 { BedTypeSchema } from "@/types/components/hotelReservation/enterDetails/bedType"
import type { BreakfastPackage } from "@/types/components/hotelReservation/enterDetails/breakfast"
import type { RoomPrice } from "@/types/components/hotelReservation/enterDetails/details"
import type { Price } from "@/types/components/hotelReservation/price"
import type { Child } from "@/types/components/hotelReservation/selectRate/selectRate"
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} : null}
|
)
}
interface PriceDetailsTableProps {
fromDate: string
toDate: string
rooms: {
adults: number
childrenInRoom: Child[] | undefined
roomType: string
roomPrice: RoomPrice
bedType?: BedTypeSchema
breakfast?: BreakfastPackage | false
}[]
totalPrice: Price
vat: number
}
export default function PriceDetailsTable({
fromDate,
toDate,
rooms,
totalPrice,
vat,
}: PriceDetailsTableProps) {
const intl = useIntl()
const lang = useLang()
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) => (
{rooms.length > 1 && (
{intl.formatMessage({ id: "Room" })} {idx + 1}
)}
{room.bedType ? (
) : null}
{room.breakfast ? (
{room.childrenInRoom?.length ? (
) : null}
) : null}
))}
|
{intl.formatMessage({ id: "Price including VAT" })}
|
{formatPrice(
intl,
totalPrice.local.price,
totalPrice.local.currency
)}
|
)
}