`use client`; import React, { useEffect } from 'react'; import Image from 'next/image'; interface LightboxProps { isOpen: boolean; images: string[]; initialIndex: number; onClose: () => void; } export default function Lightbox({ isOpen, images, initialIndex, onClose }: LightboxProps) { const [currentIndex, setCurrentIndex] = React.useState(initialIndex); useEffect(() => { if (isOpen) { document.body.style.overflow = 'hidden'; } else { document.body.style.overflow = 'unset'; } return () => { document.body.style.overflow = 'unset'; }; }, [isOpen]); if (!isOpen) return null; const prevImage = () => { setCurrentIndex((prev) => (prev === 0 ? images.length - 1 : prev - 1)); }; const nextImage = () => { setCurrentIndex((prev) => (prev === images.length - 1 ? 0 : prev + 1)); }; return (
{`Gallery
{currentIndex + 1} / {images.length}
{/* Keyboard navigation */} {isOpen && (
{ if (e.key === 'Escape') onClose(); if (e.key === 'ArrowLeft') prevImage(); if (e.key === 'ArrowRight') nextImage(); }} onClick={onClose} /> )}
); }