import * as React from 'react' import { X, File, FileImage, FileCode, FileText } from 'lucide-react' import { mergeClasses } from '../../utils/classNames' export interface FileCardProps { /** The file name to display */ fileName: string /** The file size in bytes */ fileSize: number /** Whether to show the remove button */ showRemove?: boolean /** Callback when the remove button is clicked */ onRemove?: () => void /** Optional file type override (inferred from fileName if not provided) */ fileType?: string /** Maximum width of the component (CSS value) */ maxWidth?: string /** Additional Tailwind classes */ className?: string } function getFileExtension(filename: string): string { const ext = filename.split('.').pop() return ext ? ext.toUpperCase() : 'FILE' } function getFileIcon(filename: string) { const ext = filename.split('.').pop()?.toLowerCase() if (['jpg', 'jpeg', 'png', 'gif', 'svg', 'webp'].includes(ext || '')) return if (ext === 'pdf') return if (['js', 'ts', 'jsx', 'tsx', 'py', 'java', 'cpp', 'c', 'html', 'css', 'json', 'xml'].includes(ext || '')) return return } function formatFileSize(bytes: number): string { if (bytes < 1024) return `${bytes} B` if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB` return `${(bytes / (1024 * 1024)).toFixed(1)} MB` } export const FileCard: React.FC = ({ fileName, fileSize, showRemove = false, onRemove, fileType, maxWidth = '320px', className, }) => { const extension = fileType || getFileExtension(fileName) const icon = getFileIcon(fileName) const formattedSize = formatFileSize(fileSize) const baseClasses = `flex items-center gap-2 rounded-sm border border-gray-300 bg-white py-2 ${showRemove ? 'pl-3 pr-2' : 'pl-3 pr-4'}` return ( {icon} {fileName} {extension} • {formattedSize} {showRemove && ( )} ) }