/* eslint-disable no-nested-ternary */ /* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/click-events-have-key-events */ /* eslint-disable @next/next/no-img-element */ /* eslint-disable react/no-danger */ import Image from "next/image"; import React, { useCallback } from "react"; import { useMediaQuery } from "usehooks-ts"; import NoImage from "@/assets/svg/images/no-image.svg"; import { Badge } from "@/components/ui/badge/badge"; import { Button } from "@/components/ui/button/button"; import { Carousel } from "@/components/ui/carousel/carousel"; import { HoverCard, HoverCardContent, HoverCardTrigger, } from "@/components/ui/hover-card"; import LIcon from "@/components/ui/lucid-icon/lucid-icon"; import { useLocale } from "@/hooks/useLocale"; import hasClassParents from "@/libs/helpers/hasClass"; import { cn } from "@/libs/utils"; import type { HotelListItemDiscountInformation } from "@/services/eva-display/hotel/hotel-search/hotel-search-services.types"; import styles from "./hotel-card.module.css"; interface DiscountBadgeProps { price: number; rate: number; } interface IncludedSpecification { icon?: any; tooltip?: string; text: string; } export interface HotelCardProps { id: string; className?: string; hotelName?: string; hotelLocation?: string; discount?: DiscountBadgeProps; isRecommended?: boolean; isLike?: boolean; likeButtonVisible?: boolean; images?: string[]; durationNight?: string; renderPrimaryButton?: () => React.ReactNode; renderHotelSelectButton?: () => React.ReactNode; mainSpesisification?: string; includedSpecifications?: IncludedSpecification[]; SpecificationError?: string; selectDateForPrice?: boolean; swiperContainerModifierClass?: string; price?: number; availableDateButton?: boolean; hasHygienicalMeasure: boolean; onClickPrimaryButton?: (id: string) => void; onClickLike?: (id: string) => void; loyaltyValue?: number; discountInformations?: HotelListItemDiscountInformation[]; } type AvailableButtonProps = { // eslint-disable-next-line react/no-unused-prop-types type: "desktop" | "mobile"; }; function HotelCard({ id, hotelName, hotelLocation, discount, isRecommended, isLike, likeButtonVisible = false, images, durationNight, includedSpecifications, price, selectDateForPrice, mainSpesisification, SpecificationError, availableDateButton, hasHygienicalMeasure, renderPrimaryButton, renderHotelSelectButton, onClickLike, onClickPrimaryButton, className, swiperContainerModifierClass, loyaltyValue, discountInformations, }: HotelCardProps) { const handleOnPrimaryClick = useCallback( () => onClickPrimaryButton?.(id), [id, onClickPrimaryButton], ); const isDesktop = useMediaQuery("(min-width: 768px)"); const { t } = useLocale(); const AvailableButton = useCallback( ({ type }: AvailableButtonProps) => ( /* @todo add translation for 'İncele' & 'Müsait Tarihler' */ ), [handleOnPrimaryClick], ); const extendincludedSpecifications = includedSpecifications ?.slice(3) .map(({ text }, key) =>
  • {text}
  • ); return (
    !isDesktop && !hasClassParents(e.target as HTMLElement, [ "swiper-navigation", "popover-trigger", ]) && handleOnPrimaryClick() } >
    {/* @todo - add translation for 'Öneriliyor' */} {isRecommended && ( {t("Recommended")} )} {likeButtonVisible && ( onClickLike?.(id)} /> )} {images && images?.length > 0 && ( 1} containerModifierClass={swiperContainerModifierClass} > {images?.map((image) => ( Hotel card images ))} )} {!images && ( No picture image )}
    {/* Hotel Name and Location */}
    {hasHygienicalMeasure && (
    {t("Safe Tourism Certified Hotel")}
    )}

    {hotelName}

    {hotelLocation}

    {/* Hotel Specifications - @todo it'll be complete */}
    {SpecificationError ? ( {SpecificationError} ) : ( <> {mainSpesisification && (

    {mainSpesisification}

    )} {(includedSpecifications?.length || 0) > 0 && (
    {includedSpecifications ?.slice(0, 3) .map(({ text, icon, tooltip }) => { if (icon === "masterpass") { return ( mastercard {text} {tooltip && (

    )} ); } if (text === "Ücretsiz iptal") { return ( {text} ); } return {text}; })} {discountInformations && discountInformations?.length > 0 && discountInformations?.map(({ tooltip, description }) => tooltip.trim() !== "" ? ( {description} {tooltip && (

    )} ) : ( {description} ), )} {(includedSpecifications?.length || 0) > 3 && (

    +{(includedSpecifications?.length || 0) - 3}
    Kampanya ve indirimler
      {extendincludedSpecifications}
    )}
    )} )}
    {selectDateForPrice && !availableDateButton ? (
    {/* @todo - add translation for 'Fiyat görebilmek için tarih seçin' */} {/* @todo add translation for 'Tarih Seç' */}
    ) : ( <> {/* Price & Discount Info */}
    {!!loyaltyValue && loyaltyValue > 0 && (
    {t("{{point}} Miles", { point: loyaltyValue })}

    {t("Miles")}

    {t( "The number of miles to be earned on the total cost of your stay. It will be uploaded to the guest specified as the contact person.", )}

    )} {price && ( <> {discount && !availableDateButton && ( <> {/* @todo - add translation for 'İndirim' */} % {t("{{discount}} discount", { discount: discount.rate, })} )}
    {!isDesktop && durationNight && (

    {durationNight}

    )}
    {discount && !availableDateButton && ( <> {/* @todo - add dynamic currency */}

    {/* @todo - add dynamic currency and format */} {discount.price}

    )} {/* @todo - add dynamic currency and format */}
    {price || 0.0}
    )}
    {/* Card Button and night info */}
    {price && ( <> {/* @todo - add translation for 'gece toplam' */} {isDesktop && (

    {durationNight}

    )} {/* eslint-disable-next-line no-nested-ternary */} {renderPrimaryButton ? ( renderPrimaryButton() ) : !availableDateButton ? ( renderHotelSelectButton ? ( renderHotelSelectButton() ) : ( ) ) : ( availableDateButton && )} )}
    )}
    {availableDateButton && (
    )}
    ); } export default HotelCard;