import { FiFile, FiDownload, FiImage } from "react-icons/fi"; /** * FileAttachment component - displays file attachments in messages * Supports PDF, images, and other file types */ function FileAttachment({ attachment, isDark, onDownload }) { const { name, type, url } = attachment; // Handle click to download/view const handleClick = () => { if (onDownload) { onDownload(attachment); } else if (url) { window.open(url, "_blank"); } }; // Render image attachment if (type === "image") { return (
{name} { e.target.style.display = "none"; const parent = e.target.parentElement; if (parent) { const errorDiv = document.createElement("div"); errorDiv.className = "w-full h-40 flex items-center justify-center"; errorDiv.style.background = "var(--bg-surface-tertiary)"; errorDiv.innerHTML = 'Không thể tải ảnh'; parent.appendChild(errorDiv); } }} />
); } // Render PDF attachment if (type === "pdf") { return (
{name}
PDF Document
); } // Render other file types return (
{ e.currentTarget.style.borderColor = "var(--primary)"; }} onMouseLeave={(e) => { e.currentTarget.style.borderColor = "var(--border-primary)"; }} >
{name}
{getFileExtension(name)}
); } /** * Get file extension from filename */ function getFileExtension(filename) { const ext = filename.split(".").pop().toUpperCase(); return `${ext} File`; } export default FileAttachment;