/* eslint-disable jsx-a11y/no-static-element-interactions */ /* eslint-disable jsx-a11y/click-events-have-key-events */ /* eslint-disable @next/next/no-img-element */ import type { icons } from "lucide-react"; import Image from "next/image"; import type { ReactNode } from "react"; import React, { useCallback, useEffect } from "react"; import { useWindowSize } 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 { Tooltip } from "@/components/ui/tooltip/tooltip"; import { cn } from "@/libs/utils"; import styles from "./tour-card.module.css"; interface DiscountBadgeProps { price: string; rate: number; } interface IncludedSpecification { icon?: keyof typeof icons; text: string; } export interface TourCardProps { id: string; className?: string; tourName?: string; discount?: DiscountBadgeProps; isRecommended?: boolean; isLike?: boolean; likeButtonVisible?: boolean; images?: string[]; priceInformation?: string; includedSpecifications?: IncludedSpecification[]; SpecificationError?: string; selectDateForPrice?: boolean; swiperContainerModifierClass?: string; price?: string; availableDateButton?: boolean; detailItems: { label: string; value: string; tooltip?: TourCardTooltipProps; }[]; renderPrimaryButton?: () => React.ReactNode; onClickPrimaryButton?: (id: string) => void; onClickLike?: (id: string) => void; } type AvailableButtonProps = { // eslint-disable-next-line react/no-unused-prop-types type: "desktop" | "mobile"; }; interface TourCardTooltipProps { label: ReactNode; children: ReactNode; } export function TourCardTooltip({ label, children }: TourCardTooltipProps) { return (
{children}
); } function TourCardDetailItem({ label, value, tooltip, }: { label?: ReactNode; value?: ReactNode; tooltip?: TourCardTooltipProps; }) { return ( value && (
{label}:
{value}
{!!tooltip && (
)}
) ); } function TourCard({ id, tourName, discount, isRecommended, isLike, likeButtonVisible = false, images, priceInformation, includedSpecifications, price, selectDateForPrice, SpecificationError, availableDateButton, detailItems, renderPrimaryButton, onClickLike, onClickPrimaryButton, className, swiperContainerModifierClass, }: TourCardProps) { const handleOnPrimaryClick = useCallback( () => onClickPrimaryButton?.(id), [id, onClickPrimaryButton], ); const specWrapperRef = React.useRef(null); const [contentSlice, setContentSlice] = React.useState(3); const windowSize = useWindowSize(); const isDesktop = windowSize.width > 640; const AvailableButton = useCallback( ({ type }: AvailableButtonProps) => ( /* @todo add translation for 'İncele' & 'Müsait Tarihler' */ ), [handleOnPrimaryClick], ); const extendincludedSpecifications = includedSpecifications ?.slice(contentSlice) .map(({ text }, key) =>
  • {text}
  • ); useEffect(() => { if ((specWrapperRef?.current?.offsetHeight || 0) > 60) { setContentSlice((prev) => prev - 1); } }, [specWrapperRef, contentSlice]); return (
    !isDesktop && !!handleOnPrimaryClick && handleOnPrimaryClick() } >
    {/* @todo - add translation for 'Öneriliyor' */} {isRecommended && ( Öneriliyor )} {likeButtonVisible && ( onClickLike?.(id)} /> )} {images && images?.length > 0 && ( 1} containerModifierClass={swiperContainerModifierClass} > {images?.map((image) => ( tour card images ))} )} {!images && ( No picture image )}
    {/* tour Name and Location */}

    {tourName}

    {!!detailItems?.length && (
    {detailItems.map((item) => ( ))}
    )}
    {/* tour Specifications - @todo it'll be complete */}
    {SpecificationError ? ( {SpecificationError} ) : ( (includedSpecifications?.length || 0) > 0 && (
    {includedSpecifications ?.slice(0, contentSlice) .map(({ text }) => {text})} {(includedSpecifications?.length || 0) > contentSlice && ( Kampanya ve fırsatlar
      {extendincludedSpecifications}
    } > +{(includedSpecifications?.length || 0) - contentSlice} )}
    ) )}
    {selectDateForPrice && !availableDateButton ? (
    {/* @todo - add translation for 'Fiyat görebilmek için tarih seçin' */} {/* @todo add translation for 'Tarih Seç' */}
    ) : ( <> {/* Price & Discount Info */}
    Kişi başı
    {price && ( <> {discount && !availableDateButton && ( <> {/* @todo - add translation for 'İndirim' */} %{discount.rate} İndirim )}
    {discount && !availableDateButton && ( <> {/* @todo - add dynamic currency */}

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

    )} {/* @todo - add dynamic currency and format */}
    {price || 0.0}
    {/* @todo - add translation for 'gece toplam' */}

    {priceInformation}

    )}
    {/* Card Button and night info */}
    {price && ( <> {/* @todo add translation for 'İncele' */} {/* eslint-disable-next-line no-nested-ternary */} {renderPrimaryButton ? ( renderPrimaryButton() ) : !availableDateButton ? ( ) : ( availableDateButton && )} )}
    )}
    {availableDateButton && (
    )}
    ); } export default TourCard;