import { PureComponent } from 'react'; import Box from '@mui/material/Box'; import IconButton from '@mui/material/IconButton'; import Tooltip from '@mui/material/Tooltip'; import Typography from '@mui/material/Typography'; import TextSnippetOutlinedIcon from '@mui/icons-material/TextSnippetOutlined'; import PictureAsPdfIcon from '@mui/icons-material/PictureAsPdf'; import SyncIcon from '@mui/icons-material/Sync'; import DeleteOutlineOutlinedIcon from '@mui/icons-material/DeleteOutlineOutlined'; import { tileBaseSx, TILE_SIZE } from 'dashgui/tiles'; export class Attachment extends PureComponent { handleRescan = (e) => { e?.stopPropagation?.(); const { attachment, onRescan } = this.props; if (attachment && onRescan) { onRescan(attachment); } }; handleDelete = (e) => { e?.stopPropagation?.(); const { attachment, onDelete } = this.props; if (attachment && onDelete) { onDelete(attachment); } }; handleTileClick = (e) => { const { attachment, onClick } = this.props; if (onClick && attachment) { onClick(attachment); } else if (attachment?.file instanceof Blob || attachment?.file instanceof File) { const url = URL.createObjectURL(attachment.file); window.open(url, '_blank'); } }; formatFileSize(bytes) { if (bytes == null || Number.isNaN(bytes)) return ''; if (bytes < 1024) return `${bytes} B`; if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`; return `${(bytes / (1024 * 1024)).toFixed(1)} MB`; } render() { const { attachment, disabled, sx } = this.props; const thumbnail = attachment?.thumbnail; const name = attachment?.name || 'Dokument'; const size = attachment?.size; const isPdf = attachment?.type === 'application/pdf' || name.toLowerCase().endsWith('.pdf'); const isText = attachment?.type?.startsWith('text/') || name.toLowerCase().endsWith('.txt'); return ( {/* Thumbnail, Text preview, or Fallback Icon */} {thumbnail ? ( ) : isText ? ( TXT {attachment?.text ? attachment.text.slice(0, 300) : 'Textdatei'} ) : ( )} {/* Action buttons: Rescan (for PDF) and Delete */} e.stopPropagation()} > {isPdf ? ( ) : null} {/* Bottom file metadata overlay */} {name} {size ? ( {this.formatFileSize(size)} ) : null} ); } } export default Attachment;