import React, { useState, useRef, useEffect } from "react"; import { X, AlertTriangle, ExternalLink, Image as ImageIcon } from "lucide-react"; import type { ImageAttachment } from "@/lib/tauriCommands"; interface ImageGalleryProps { images: ImageAttachment[]; onDelete?: (attachment: ImageAttachment) => void; showWarning?: boolean; } export function ImageGallery({ images, onDelete, showWarning = true }: ImageGalleryProps) { const [selectedImage, setSelectedImage] = useState(null); const [isModalOpen, setIsModalOpen] = useState(false); const modalRef = useRef(null); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape" && isModalOpen) { setIsModalOpen(false); setSelectedImage(null); } }; window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [isModalOpen]); if (images.length === 0) return null; const base64ToDataUrl = (base64: string, mimeType: string): string => { if (base64.startsWith("data:image/")) { return base64; } return `data:${mimeType};base64,${base64}`; }; const getPreviewUrl = (attachment: ImageAttachment): string => { if (attachment.file_path && attachment.file_path.length > 0) { return `file://${attachment.file_path}`; } return base64ToDataUrl(attachment.upload_hash, attachment.mime_type); }; const isWebSource = (image: ImageAttachment): boolean => { return image.file_path.length > 0 && (image.file_path.startsWith("http://") || image.file_path.startsWith("https://")); }; return (
{showWarning && (
⚠️ PII cannot be automatically redacted from images. Use at your own risk.
)} {images.some(img => isWebSource(img)) && (
⚠️ Some images appear to be from web sources. Ensure you have permission to share.
)}
{images.map((image, idx) => (

{image.file_name}

{image.is_paste ? "Paste" : "Upload"} · {(image.file_size / 1024).toFixed(1)} KB

{onDelete && ( )}
))}
{isModalOpen && selectedImage && (
{ setIsModalOpen(false); setSelectedImage(null); }} >
e.stopPropagation()} >

{selectedImage.file_name}

{selectedImage.file_name}
Type: {selectedImage.mime_type}
Size: {(selectedImage.file_size / 1024).toFixed(2)} KB
Source: {selectedImage.is_paste ? "Paste" : "File"}
)}
); } export default ImageGallery;