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 (
{/* ── Image area ── */}
{/* Toolbar */}
e.stopPropagation()} style={{ position: 'absolute', top: 0, right: 0, display: 'flex', gap: 4, padding: 10, zIndex: 10 }} > setShowInfo(s => !s)} active={showInfo} title="Info [i]" > ✕
{/* Left nav */} {index > 0 && ( { e.stopPropagation(); onChange(index - 1); }}>‹ )} {/* Right nav */} {index < photos.length - 1 && ( { e.stopPropagation(); onChange(index + 1); }}>› )} e.stopPropagation()} style={{ maxWidth: '100%', maxHeight: 'calc(100vh - 20px)', objectFit: 'contain', display: 'block', }} />
{/* ── Detail panel ── */} {showInfo && (
)}
); } function IconBtn({ onClick, active, title, children }) { return ( ); } function NavBtn({ side, onClick, children }) { return ( ); } function InfoIcon() { return ( ); }