"use client" import { useParams } from "next/dist/client/components/navigation" import { memo, useCallback } from "react" import { useIntl } from "react-intl" import { HotelLogo, MaterialIcon } from "@scandic-hotels/design-system/Icons" import { selectRate } from "@/constants/routes/hotelReservation" import { useHotelsMapStore } from "@/stores/hotels-map" import { FacilityToIcon } from "@/components/ContentType/HotelPage/data" import ImageGallery from "@/components/ImageGallery" 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 Body from "@/components/TempDesignSystem/Text/Body" import Caption from "@/components/TempDesignSystem/Text/Caption" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" import { Tooltip } from "@/components/TempDesignSystem/Tooltip" import { mapApiImagesToGalleryImages } from "@/utils/imageGallery" import { getSingleDecimal } from "@/utils/numberFormatting" import ReadMore from "../ReadMore" import TripAdvisorChip from "../TripAdvisorChip" import HotelChequeCard from "./HotelChequeCard" import HotelPointsRow from "./HotelPointsRow" import HotelPriceCard from "./HotelPriceCard" import HotelVoucherCard from "./HotelVoucherCard" import NoPriceAvailableCard from "./NoPriceAvailableCard" import { hotelCardVariants } from "./variants" import styles from "./hotelCard.module.css" import { HotelCardListingTypeEnum } from "@/types/components/hotelReservation/selectHotel/hotelCardListingProps" import type { HotelCardProps } from "@/types/components/hotelReservation/selectHotel/hotelCardProps" import { RateTypeEnum } from "@/types/enums/rateType" import type { Lang } from "@/constants/languages" function HotelCard({ hotelData: { availability, hotel }, isUserLoggedIn, state = "default", type = HotelCardListingTypeEnum.PageListing, bookingCode = "", }: HotelCardProps) { const params = useParams() const lang = params.lang as Lang const intl = useIntl() const { setActiveHotelPin, setActiveHotelCard } = useHotelsMapStore() const handleMouseEnter = useCallback(() => { setActiveHotelPin(hotel.name) }, [setActiveHotelPin, hotel]) const handleMouseLeave = useCallback(() => { setActiveHotelPin(null) setActiveHotelCard(null) }, [setActiveHotelPin, setActiveHotelCard]) const amenities = hotel.detailedFacilities.slice(0, 5) const classNames = hotelCardVariants({ type, state, }) const addressStr = `${hotel.address.streetAddress}, ${hotel.address.city}` const galleryImages = mapApiImagesToGalleryImages(hotel.galleryImages || []) const fullPrice = availability.productType?.public?.rateType === RateTypeEnum.Regular || availability.productType?.member?.rateType === RateTypeEnum.Regular const price = availability.productType const userHasEnoughPoints = price?.redemptions?.some((r) => r.hasEnoughPoints) const notEnoughPointsLabel = intl.formatMessage({ id: "Not enough points" }) return (
{hotel.ratings?.tripAdvisor && ( )}
{hotel.name}
{addressStr}
{addressStr}
{intl.formatMessage( { id: "{number} km to city center" }, { number: getSingleDecimal( hotel.location.distanceToCentre / 1000 ), } )}
{hotel.hotelContent.texts.descriptions?.short}
{amenities.map((facility) => { const Icon = ( ) return (
{Icon && Icon} {facility.name}
) })}
{!availability.productType ? ( ) : ( <> {bookingCode && ( } > {bookingCode} )} {(!isUserLoggedIn || !price?.member || (bookingCode && !fullPrice)) && price?.public && ( )} {availability.productType.member && ( )} {price?.voucher && ( )} {price?.bonusCheque && ( )} {price?.redemptions?.length ? (
{intl.formatMessage({ id: "Available rates" })} {price.redemptions.map((redemption) => ( ))}
) : null} {price?.redemptions?.length && !userHasEnoughPoints ? ( ) : ( )} )}
) } export default memo(HotelCard)