import { Dialog, Modal, ModalOverlay } from "react-aria-components" import { useIntl } from "react-intl" import { formatPrice } from "@scandic-hotels/common/utils/numberFormatting" import Caption from "@scandic-hotels/design-system/Caption" import { MaterialIcon } from "@scandic-hotels/design-system/Icons/MaterialIcon" import { OldDSButton as Button } from "@scandic-hotels/design-system/OldDSButton" import Subtitle from "@scandic-hotels/design-system/Subtitle" import Title from "@scandic-hotels/design-system/Title" import { Typography } from "@scandic-hotels/design-system/Typography" import { useEnterDetailsStore } from "../../../stores/enter-details" import { calculateTotalRoomPrice } from "../Payment/helpers" import PriceChangeSummary from "./PriceChangeSummary" import styles from "./priceChangeDialog.module.css" import type { PriceChangeData } from "../PriceChangeData" type PriceDetailsState = { newTotalPrice: number roomPrices: { prevPrice: number; newPrice?: number }[] } type PriceChangeDialogProps = { isOpen: boolean priceChangeData: PriceChangeData prevTotalPrice: number currency: string onCancel: () => void onAccept: () => void } export default function PriceChangeDialog({ isOpen, priceChangeData, prevTotalPrice, currency, onCancel, onAccept, }: PriceChangeDialogProps) { const intl = useIntl() const title = intl.formatMessage({ id: "enterDetails.priceChangeDialog.title", defaultMessage: "Price change", }) const rooms = useEnterDetailsStore((state) => state.rooms) const { newTotalPrice, roomPrices } = rooms.reduce( (acc, room, idx) => { const roomPrice = room.room.roomPrice.perStay.local.price const priceChange = priceChangeData[idx] const { totalPrice } = calculateTotalRoomPrice( room, priceChange?.roomPrice ) acc.newTotalPrice += totalPrice acc.roomPrices.push({ prevPrice: roomPrice, newPrice: priceChange?.roomPrice, }) return acc }, { newTotalPrice: 0, roomPrices: [] } ) const roomSelectionMsg = intl.formatMessage( { id: "enterDetails.priceChangeDialog.descriptionPreviousRooms", defaultMessage: "{totalRooms, plural, one {room} other {rooms}}", }, { totalRooms: rooms.length, } ) const newRoomSelectionMsg = intl.formatMessage( { id: "enterDetails.priceChangeDialog.descriptionNewRooms", defaultMessage: "{totalRooms, plural, one {a new room} other {new rooms}}", }, { totalRooms: rooms.length, } ) return (
{title}

{intl.formatMessage( { id: "enterDetails.priceChangeDialog.description", defaultMessage: "Prices have increased since you selected your {roomSelection}.{linebreak} To continue your booking, accept the updated price,{linebreak} or go back to select {newRoomSelection}.", }, { roomSelection: roomSelectionMsg, newRoomSelection: newRoomSelectionMsg, linebreak:
, } )}

{intl.formatMessage({ id: "enterDetails.priceChangeDialog.newTotalLabel", defaultMessage: "New total", })}
{formatPrice(intl, prevTotalPrice, currency)}

{formatPrice(intl, newTotalPrice, currency)}

) }