"use client"; import Image from "next/image"; import Link from "next/link"; import { ChevronLeft, ChevronRight } from "lucide-react"; import { useRef, useState } from "react"; // Galería deslizable de la tarjeta de producto: permite ver todas las // imágenes desde el listado sin entrar al producto. En móvil se desliza // con el dedo (scroll-snap nativo); en escritorio aparecen flechas al // pasar el mouse. Cada imagen sigue siendo un link a la ficha. export function ProductCardGallery({ images, name, href, priority = false, }: { images: string[]; name: string; href: string; priority?: boolean; }) { const scroller = useRef(null); const [index, setIndex] = useState(0); const total = images.length; const goTo = (target: number) => { const node = scroller.current; if (!node) return; const next = Math.max(0, Math.min(total - 1, target)); node.scrollTo({ left: next * node.clientWidth, behavior: "smooth" }); }; const onScroll = () => { const node = scroller.current; if (!node || node.clientWidth === 0) return; setIndex(Math.round(node.scrollLeft / node.clientWidth)); }; return ( <>
1 ? onScroll : undefined} className="flex h-full snap-x snap-mandatory overflow-x-auto [overscroll-behavior-x:contain] [scrollbar-width:none] [&::-webkit-scrollbar]:hidden" > {images.map((src, slide) => ( 1 ? `${name}, imagen ${slide + 1} de ${total}` : name} tabIndex={slide === 0 ? 0 : -1} > {slide ))}
{total > 1 && ( <>
{images.map((src, dot) => ( ))}
)} ); }