'use client' import { format, isPast, addDays } from 'date-fns' import { FileText, Image as ImageIcon, File } from 'lucide-react' interface DocumentData { id: string title: string category: string fileName: string fileSize: number mimeType: string dateTaken: string | null expiryDate: string | null notes: string | null createdAt: string } interface DocumentCardProps { document: DocumentData onView: (doc: DocumentData) => void } const CATEGORY_BADGES: Record = { LAB_REPORT: 'bg-blue-100 text-blue-700', SCAN: 'bg-purple-100 text-purple-700', INSURANCE: 'bg-green-100 text-green-700', ID_CARD: 'bg-orange-100 text-orange-700', PRESCRIPTION: 'bg-pink-100 text-pink-700', OTHER: 'bg-secondary-100 text-secondary-700', } const CATEGORY_LABELS: Record = { LAB_REPORT: 'Lab Report', SCAN: 'Scan', INSURANCE: 'Insurance', ID_CARD: 'ID Card', PRESCRIPTION: 'Prescription', OTHER: 'Other', } function FileIcon({ mimeType }: { mimeType: string }) { if (mimeType === 'application/pdf') return if (mimeType.startsWith('image/')) 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 function DocumentCard({ document: doc, onView }: DocumentCardProps) { const badge = CATEGORY_BADGES[doc.category] || CATEGORY_BADGES.OTHER const label = CATEGORY_LABELS[doc.category] || doc.category const isExpiringSoon = doc.expiryDate && !isPast(new Date(doc.expiryDate)) && isPast(addDays(new Date(), -30)) const isExpired = doc.expiryDate && isPast(new Date(doc.expiryDate)) return (
onView(doc)} className="bg-surface rounded-card border border-border p-4 cursor-pointer hover:shadow-card-hover transition-shadow" >

{doc.title}

{label} {formatFileSize(doc.fileSize)} {doc.dateTaken && ( {format(new Date(doc.dateTaken), 'MMM d, yyyy')} )}
{/* Expiry indicators */} {isExpired && ( Expired )} {isExpiringSoon && !isExpired && ( Expiring soon )}
) }