import React from 'react';
import type { MessageBlock } from '@/store/commStore';
import { Download, FileText } from 'lucide-react';
interface FileBlockProps {
block: MessageBlock;
}
function formatFileSize(bytes: number | undefined): string {
if (typeof bytes !== 'number' || bytes <= 0) return '';
if (bytes < 1024) return `${bytes} B`;
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
if (bytes < 1024 * 1024 * 1024) return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
return `${(bytes / (1024 * 1024 * 1024)).toFixed(1)} GB`;
}
const fileIcon = (
);
const downloadIcon = (
);
const FileBlock: React.FC = ({ block }) => {
const { url, name, size } = block.block_data;
if (!url && !name) {
return null;
}
const fileName: string = name || 'Datei';
const fileSizeLabel = formatFileSize(size);
return (
{fileIcon}
{fileName}
{fileSizeLabel && (
{fileSizeLabel}
)}
{url && (
{downloadIcon}
)}
);
};
export default FileBlock;