import { useState, useEffect } from 'react'; import DetailPanel from './DetailPanel.jsx'; export default function Lightbox({ photos, index, onClose, onChange }) { const [showInfo, setShowInfo] = useState(false); const photo = photos[index]; useEffect(() => { function onKey(e) { // Don't hijack shortcuts while typing in the detail panel if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA' || e.target.tagName === 'SELECT') return; if (e.key === 'Escape') onClose(); if (e.key === 'ArrowLeft' && index > 0) onChange(index - 1); if (e.key === 'ArrowRight' && index < photos.length - 1) onChange(index + 1); if (e.key === 'i') setShowInfo(s => !s); } window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); }, [index, photos.length, onClose, onChange]); useEffect(() => { document.body.style.overflow = 'hidden'; return () => { document.body.style.overflow = ''; }; }, []); if (!photo) return null; return (