import { useEffect, useCallback } from "react"; interface ImageLightboxProps { images: string[]; index: number; onClose: () => void; onNavigate: (index: number) => void; } export function ImageLightbox({ images, index, onClose, onNavigate }: ImageLightboxProps) { const hasPrev = index > 0; const hasNext = index < images.length - 1; const handleKeyDown = useCallback((e: KeyboardEvent) => { if (e.key === "Escape") { e.stopImmediatePropagation(); onClose(); } if (e.key === "ArrowLeft" && hasPrev) onNavigate(index - 1); if (e.key === "ArrowRight" && hasNext) onNavigate(index + 1); }, [onClose, onNavigate, index, hasPrev, hasNext]); useEffect(() => { document.addEventListener("keydown", handleKeyDown); return () => document.removeEventListener("keydown", handleKeyDown); }, [handleKeyDown]); return (
{/* Close button */} {/* Counter */} {images.length > 1 && (
{index + 1} / {images.length}
)} {/* Prev arrow */} {hasPrev && ( )} {/* Image — click to close (same gesture as clicking the backdrop) */} {`Image {/* Next arrow */} {hasNext && ( )}
); }