"use client"; import Image from "next/image"; import { useCallback, useEffect, useState } from "react"; import { Reveal } from "@/components/Reveal"; function ChevronIcon({ direction, className }: { direction: "next" | "prev"; className?: string }) { const d = direction === "next" ? "M19 12H5m0 0 6-6m-6 6 6 6" : "M5 12h14m0 0-6-6m6 6-6 6"; return ( ); } /** * The grid stays exactly as before; clicking a thumbnail opens it full-size * with prev/next controls — a lightbox/slideshow over the same image list. */ export function ProjectGalleryLightbox({ images, alt }: { images: string[]; alt: string }) { const [openIndex, setOpenIndex] = useState(null); const close = useCallback(() => setOpenIndex(null), []); const showNext = useCallback( () => setOpenIndex((i) => (i === null ? null : (i + 1) % images.length)), [images.length], ); const showPrev = useCallback( () => setOpenIndex((i) => (i === null ? null : (i - 1 + images.length) % images.length)), [images.length], ); useEffect(() => { if (openIndex === null) return; document.body.style.overflow = "hidden"; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") close(); if (e.key === "ArrowRight") showPrev(); // RTL: right arrow moves to the previous item if (e.key === "ArrowLeft") showNext(); }; window.addEventListener("keydown", onKey); return () => { document.body.style.overflow = ""; window.removeEventListener("keydown", onKey); }; }, [openIndex, close, showNext, showPrev]); return ( <> {images.map((url, i) => ( setOpenIndex(i)} aria-label={`مشاهده بزرگتر تصویر ${i + 1}`} className="group relative block aspect-[4/3] w-full overflow-hidden bg-ink" > ))} {openIndex !== null && ( {openIndex + 1} / {images.length} {images.length > 1 && ( <> { e.stopPropagation(); showPrev(); }} aria-label="تصویر قبلی" className="absolute start-3 top-1/2 flex h-12 w-12 -translate-y-1/2 items-center justify-center rounded-full text-white/80 transition-colors hover:bg-white/10 hover:text-white sm:start-6" > { e.stopPropagation(); showNext(); }} aria-label="تصویر بعدی" className="absolute end-3 top-1/2 flex h-12 w-12 -translate-y-1/2 items-center justify-center rounded-full text-white/80 transition-colors hover:bg-white/10 hover:text-white sm:end-6" > > )} e.stopPropagation()} > )} > ); }