import { useState, useEffect } from 'react'; import { X, ChevronLeft, ChevronRight, Download, Trash2 } from 'lucide-react'; import { api } from '../api/client'; import { Button } from './Button'; import { ConfirmModal } from './ConfirmModal'; interface PhotoGalleryModalProps { archiveId: number; archiveName: string; photos: string[]; onClose: () => void; onDelete?: (filename: string) => void; } export function PhotoGalleryModal({ archiveId, archiveName, photos, onClose, onDelete, }: PhotoGalleryModalProps) { const [currentIndex, setCurrentIndex] = useState(0); const [showDeleteConfirm, setShowDeleteConfirm] = useState(false); // Keyboard navigation useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); if (e.key === 'ArrowLeft') setCurrentIndex((i) => Math.max(0, i - 1)); if (e.key === 'ArrowRight') setCurrentIndex((i) => Math.min(photos.length - 1, i + 1)); }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [onClose, photos.length]); // Reset index if photos change useEffect(() => { if (currentIndex >= photos.length) { setCurrentIndex(Math.max(0, photos.length - 1)); } }, [photos.length, currentIndex]); if (photos.length === 0) { onClose(); return null; } const currentPhoto = photos[currentIndex]; const photoUrl = api.getArchivePhotoUrl(archiveId, currentPhoto); const handleDownload = () => { const link = document.createElement('a'); link.href = photoUrl; link.download = `${archiveName}_photo_${currentIndex + 1}.jpg`; link.click(); }; const handleDelete = () => { if (onDelete) { setShowDeleteConfirm(true); } }; return (
Photo {currentIndex + 1} of {photos.length}