import { FileText, Image, FileSpreadsheet, File, FileType, Film } from 'lucide-react'

const ICON_MAP: Record<string, { icon: typeof FileText; color: string }> = {
  'application/pdf': { icon: FileText, color: 'text-red-500' },
  'image/jpeg': { icon: Image, color: 'text-blue-500' },
  'image/png': { icon: Image, color: 'text-blue-500' },
  'image/webp': { icon: Image, color: 'text-blue-500' },
  'image/gif': { icon: Image, color: 'text-blue-500' },
  'application/vnd.openxmlformats-officedocument.wordprocessingml.document': { icon: FileType, color: 'text-blue-600' },
  'application/msword': { icon: FileType, color: 'text-blue-600' },
  'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': { icon: FileSpreadsheet, color: 'text-green-600' },
  'application/vnd.ms-excel': { icon: FileSpreadsheet, color: 'text-green-600' },
  'text/csv': { icon: FileSpreadsheet, color: 'text-green-600' },
  'text/plain': { icon: FileText, color: 'text-muted-foreground' },
  'video/mp4': { icon: Film, color: 'text-purple-500' },
}

export function FileIcon({ contentType, className = 'h-8 w-8' }: { contentType: string; className?: string }) {
  const match = ICON_MAP[contentType] ?? { icon: File, color: 'text-muted-foreground' }
  const Icon = match.icon
  return <Icon className={`${className} ${match.color}`} />
}

export function formatFileSize(bytes: number): string {
  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`
}
