"use client"; import { useEffect, useState } from "react"; import Image from "next/image"; import { ChevronLeft, ChevronRight, X } from "lucide-react"; export function Gallery({ images, alt }: { images: string[]; alt: string }) { const [active, setActive] = useState(null); useEffect(() => { if (active === null) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") setActive(null); if (e.key === "ArrowRight") setActive((i) => (i === null ? null : (i + 1) % images.length)); if (e.key === "ArrowLeft") setActive((i) => i === null ? null : (i - 1 + images.length) % images.length, ); }; document.body.style.overflow = "hidden"; window.addEventListener("keydown", onKey); return () => { document.body.style.overflow = ""; window.removeEventListener("keydown", onKey); }; }, [active, images.length]); return ( <>
{images.map((src, i) => ( ))}
{active !== null && (
setActive(null)} > {images.length > 1 && ( <> )}
e.stopPropagation()} > {`${alt}

{active + 1} / {images.length}

)} ); }