import { useEffect, type ReactNode } from 'react' import { useTranslation } from 'react-i18next' type ImageLightboxProps = { image: string | null alt?: string onClose: () => void action?: ReactNode } export function ImageLightbox({ image, alt = '', onClose, action }: ImageLightboxProps) { const { t } = useTranslation() const translated = (key: string, fallback: string, values?: Record) => { const value = t(key, values) return value === key ? fallback : value } useEffect(() => { if (!image) return undefined const handleKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') onClose() } document.addEventListener('keydown', handleKeyDown) const previousOverflow = document.body.style.overflow document.body.style.overflow = 'hidden' return () => { document.removeEventListener('keydown', handleKeyDown) document.body.style.overflow = previousOverflow } }, [image, onClose]) if (!image) return null return (
event.stopPropagation()}> {alt {action ?
{action}
: null}
) }