/** * Fullscreen image slideshow for admin feedback / media lists. */ import { useEffect, useCallback } from 'react' import { resolveMediaUrl } from './MediaValue' type Props = { urls: string[] index: number onClose: () => void onIndex: (i: number) => void } export function ImageLightbox({ urls, index, onClose, onIndex }: Props) { const total = urls.length const safeIndex = total ? ((index % total) + total) % total : 0 const src = total ? resolveMediaUrl(urls[safeIndex]) : '' const prev = useCallback(() => { if (!total) return onIndex((safeIndex - 1 + total) % total) }, [onIndex, safeIndex, total]) const next = useCallback(() => { if (!total) return onIndex((safeIndex + 1) % total) }, [onIndex, safeIndex, total]) useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() if (e.key === 'ArrowLeft') prev() if (e.key === 'ArrowRight') next() } window.addEventListener('keydown', onKey) const prevOverflow = document.body.style.overflow document.body.style.overflow = 'hidden' return () => { window.removeEventListener('keydown', onKey) document.body.style.overflow = prevOverflow } }, [onClose, prev, next]) if (!total) return null return (