import { memo, useState, type MouseEvent as ReactMouseEvent } 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 ? (
) => {
if (event.button !== 0) {
return;
}
setIsLightboxOpen(true);
}}
onKeyDown={(event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
setIsLightboxOpen(true);
}
}}
className="w-full h-full cursor-zoom-in"
title={t('image.openTitle')}
>
) : (
{t('image.empty')}
)}
{imageUrls.length > 1 && (
{imageUrls.map((url, index) => (
))}
)}
{
setIsLightboxOpen(false);
setZoom(1);
}}
/>
);
});