// src/components/product/ProductImageGallery.tsx 'use client'; import { useState } from 'react'; import Image from 'next/image'; import { WooCommerceImage } from '@/types/woocommerce'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { ChevronLeft, ChevronRight, Expand, Heart } from 'lucide-react'; import { cn } from '@/lib/utils'; import { Dialog, DialogContent, DialogTrigger, } from '@/components/ui/dialog'; interface ProductImageGalleryProps { images: WooCommerceImage[]; productName: string; isOnSale?: boolean; discountPercentage?: number; isFeatured?: boolean; } export default function ProductImageGallery({ images, productName, isOnSale = false, discountPercentage = 0, isFeatured = false, }: ProductImageGalleryProps): JSX.Element { const [currentImageIndex, setCurrentImageIndex] = useState(0); const [isWishlisted, setIsWishlisted] = useState(false); const hasMultipleImages = images.length > 1; const currentImage = images[currentImageIndex] || images[0]; const goToPrevious = (): void => { setCurrentImageIndex((prev) => prev === 0 ? images.length - 1 : prev - 1 ); }; const goToNext = (): void => { setCurrentImageIndex((prev) => prev === images.length - 1 ? 0 : prev + 1 ); }; const goToImage = (index: number): void => { setCurrentImageIndex(index); }; const toggleWishlist = (): void => { setIsWishlisted(!isWishlisted); }; if (!currentImage) { return (
Aucune image disponible
); } return (
{/* Main Image */}
{currentImage.alt {/* Badges */}
{isOnSale && discountPercentage > 0 && ( -{discountPercentage}% )} {isFeatured && ( Nouveauté )}
{/* Wishlist Button */} {/* Navigation Arrows */} {hasMultipleImages && ( <> )} {/* Expand Button */}
{currentImage.alt
{/* Image Counter */} {hasMultipleImages && (
{currentImageIndex + 1} / {images.length}
)}
{/* Thumbnail Navigation */} {hasMultipleImages && (
{images.map((image, index) => ( ))}
)} {/* Mobile Dots Indicator */} {hasMultipleImages && (
{images.map((_, index) => (
)}
); }