import { FileIcon, XIcon } from "lucide-react"; import { cn } from "@/lib/utils"; import type { AttachmentItem, DisplayMode } from "./types"; interface AttachmentCardProps { /** Unified attachment item (uploaded or local file) */ item: AttachmentItem; mode: DisplayMode; onRemove?: () => void; onClick?: () => void; className?: string; showThumbnail?: boolean; } /** * Unified attachment card component for all file types * Renders differently based on mode (edit/view) and file category */ const AttachmentCard = ({ item, mode, onRemove, onClick, className, showThumbnail = true }: AttachmentCardProps) => { const { category, filename, thumbnailUrl, sourceUrl } = item; const isMedia = category === "image" || category === "video"; // Editor mode - compact badge style with optional thumbnail if (mode === "edit") { return (
{showThumbnail && category === "image" && thumbnailUrl ? ( {filename} ) : ( )} {filename} {onRemove && ( )}
); } // View mode - specialized rendering for media if (isMedia) { if (category === "image") { return ( { const target = e.target as HTMLImageElement; // Fallback to source URL if thumbnail fails if (target.src.includes("?thumbnail=true")) { target.src = sourceUrl; } }} onClick={onClick} decoding="async" loading="lazy" alt={filename} /> ); } else if (category === "video") { return (