// src/components/product/RelatedProducts.tsx 'use client'; import { WooCommerceProduct } from '@/types/woocommerce'; import ProductCard from './ProductCard'; import { Button } from '@/components/ui/button'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import { useRef, useState } from 'react'; import { cn } from '@/lib/utils'; interface RelatedProductsProps { products: WooCommerceProduct[]; title?: string; className?: string; } export default function RelatedProducts({ products, title = "Produits similaires", className = '' }: RelatedProductsProps): JSX.Element { const scrollContainerRef = useRef(null); const [canScrollLeft, setCanScrollLeft] = useState(false); const [canScrollRight, setCanScrollRight] = useState(true); const checkScrollButtons = (): void => { if (scrollContainerRef.current) { const { scrollLeft, scrollWidth, clientWidth } = scrollContainerRef.current; setCanScrollLeft(scrollLeft > 0); setCanScrollRight(scrollLeft < scrollWidth - clientWidth - 1); } }; const scrollLeft = (): void => { if (scrollContainerRef.current) { scrollContainerRef.current.scrollBy({ left: -320, // Largeur d'une carte + gap behavior: 'smooth' }); } }; const scrollRight = (): void => { if (scrollContainerRef.current) { scrollContainerRef.current.scrollBy({ left: 320, // Largeur d'une carte + gap behavior: 'smooth' }); } }; if (products.length === 0) { return <>; } return (
{/* Header */}

{title}

{/* Navigation Buttons - Desktop */}
{/* Products Scroll Container */}
{products.map((product, index) => (
))}
{/* Gradient Overlays */}
{/* Mobile Navigation Dots */}
{products.map((_, index) => (
{/* Alternative: Grid Layout for smaller screens */}
{products.slice(0, 4).map((product) => ( ))}
); }