import { ChevronLeft, ChevronRight } from 'lucide-react'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; type ImagePreviewModalProps = { open: boolean; onOpenChange: (open: boolean) => void; src: string | null; title?: string; alt?: string; sources?: string[]; }; export function ImagePreviewModal({ open, onOpenChange, src, title, alt = 'Preview', sources, }: ImagePreviewModalProps) { const allImages = sources && sources.length > 0 ? sources : src ? [src] : []; const [currentIndex, setCurrentIndex] = useState(0); const currentSrc = allImages[currentIndex] ?? src; const hasMultiple = allImages.length > 1; function handlePrev() { setCurrentIndex((prev) => prev === 0 ? allImages.length - 1 : prev - 1, ); } function handleNext() { setCurrentIndex((prev) => prev === allImages.length - 1 ? 0 : prev + 1, ); } return ( { if (!v) { setCurrentIndex(0); } onOpenChange(v); }} > {title && ( {title} )} {currentSrc && (
{alt} {hasMultiple && ( <>
{currentIndex + 1} / {allImages.length}
)}
)}
); }