import { memo, useState } from 'react'; import { ImageLightbox } from './image-preview/lightbox'; import { useImageDownload } from './image-preview/use-image-download'; import { useI18n } from '../i18n'; interface ImagePreviewProps { imageUrls: string[]; } export const ImagePreview = memo(function ImagePreview({ imageUrls }: ImagePreviewProps) { const { t } = useI18n(); const [activeIndex, setActiveIndex] = useState(0); const [isLightboxOpen, setIsLightboxOpen] = useState(false); const [zoom, setZoom] = useState(1); const { isDownloadingSingle, isDownloadingAll, handleDownloadAll, handleDownloadSingle } = useImageDownload(imageUrls); const safeActiveIndex = Math.min(activeIndex, Math.max(0, imageUrls.length - 1)); const activeImage = imageUrls[safeActiveIndex]; const hasImages = imageUrls.length > 0; return (

{t('image.title')}

{activeImage ? ( ) : (

{t('image.empty')}

)}
{imageUrls.length > 1 && (
{imageUrls.map((url, index) => ( ))}
)} setZoom((z) => Math.max(0.5, Math.round((z - 0.1) * 10) / 10))} onZoomIn={() => setZoom((z) => Math.min(3, Math.round((z + 0.1) * 10) / 10))} onClose={() => { setIsLightboxOpen(false); setZoom(1); }} />
); });