"use client" import { useState } from "react" import { useIntl } from "react-intl" import { Typography } from "@scandic-hotels/design-system/Typography" import { BookingStatusEnum } from "@/constants/booking" import { dt } from "@/lib/dt" import { BookingCodeIcon, CheckCircleIcon } from "@/components/Icons" import CrossCircleIcon from "@/components/Icons/CrossCircle" import SkeletonShimmer from "@/components/SkeletonShimmer" import Button from "@/components/TempDesignSystem/Button" import Divider from "@/components/TempDesignSystem/Divider" import IconChip from "@/components/TempDesignSystem/IconChip" import Link from "@/components/TempDesignSystem/Link" import Caption from "@/components/TempDesignSystem/Text/Caption" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import { useGuaranteePaymentFailedToast } from "@/hooks/booking/useGuaranteePaymentFailedToast" import useLang from "@/hooks/useLang" import { formatPrice } from "@/utils/numberFormatting" import ManageStay from "../ManageStay" import { useMyStayRoomDetailsStore } from "../stores/myStayRoomDetailsStore" import { useMyStayTotalPriceStore } from "../stores/myStayTotalPrice" import styles from "./referenceCard.module.css" import type { Hotel } from "@/types/hotel" import type { BookingConfirmation } from "@/types/trpc/routers/booking/confirmation" import { type CreditCard, type User } from "@/types/user" interface ReferenceCardProps { booking: BookingConfirmation["booking"] hotel: Hotel user: User | null savedCreditCards: CreditCard[] | null refId: string } export function ReferenceCard({ booking, hotel, user, savedCreditCards, refId, }: ReferenceCardProps) { const [bookingStatus, setBookingStatus] = useState(booking.reservationStatus) const intl = useIntl() const lang = useLang() const { totalPrice, currencyCode } = useMyStayTotalPriceStore() const { rooms } = useMyStayRoomDetailsStore() const fromDate = rooms[0] ? dt(rooms[0].checkInDate).locale(lang) : dt(booking.checkInDate).locale(lang) const toDate = rooms[0] ? dt(rooms[0].checkOutDate).locale(lang) : dt(booking.checkOutDate).locale(lang) const isCancelled = bookingStatus === BookingStatusEnum.Cancelled useGuaranteePaymentFailedToast() const directionsUrl = `https://www.google.com/maps/dir/?api=1&destination=${hotel.location.latitude},${hotel.location.longitude}` const adults = booking.adults + (booking.linkedReservations?.reduce( (acc, linkedReservation) => acc + linkedReservation.adults, 0 ) ?? 0) const children = booking.childrenAges.length + (booking.linkedReservations?.reduce( (acc, linkedReservation) => acc + linkedReservation.children, 0 ) ?? 0) const adultsMsg = intl.formatMessage( { id: "{adults, plural, one {# adult} other {# adults}}" }, { adults: adults, } ) const childrenMsg = intl.formatMessage( { id: "{children, plural, one {# child} other {# children}}", }, { children: children, } ) const adultsOnlyMsg = adultsMsg const adultsAndChildrenMsg = [adultsMsg, childrenMsg].join(", ") return (
{intl.formatMessage({ id: "Booking guaranteed." })} {" "} {intl.formatMessage({ id: "Your stay remains available for check-in after 18:00.", })}