import React from 'react'; import { FiFile, FiImage } from 'react-icons/fi'; import Typography from '../ui/Typography'; import { cn } from '../../lib/utils'; interface AttachmentDisplayProps { attachments: Array<{ name: string; data: string; type: string; size: number; }>; onImageClick?: (imageData: string, imageName: string) => void; } /** * Component to display message attachments with proper file type handling * Supports images with preview and click handling for modal display */ const AttachmentDisplay: React.FC = ({ attachments, onImageClick, }) => { return (
{attachments.map((attachment, index) => { const sizeStr = attachment.size > 1024 * 1024 ? `${(attachment.size / (1024 * 1024)).toFixed(1)}MB` : `${(attachment.size / 1024).toFixed(1)}KB`; const isImage = attachment.type.startsWith('image/'); return (
onImageClick( `data:${attachment.type};base64,${attachment.data}`, attachment.name ) : undefined } >
{isImage ? ( ) : ( )}
{attachment.name} {sizeStr} • {attachment.type}
{isImage && (
{attachment.name}
)}
); })}
); }; export default AttachmentDisplay;