'use client'; import { Download, Eye, FileText, Film, Image, MoreHorizontal, Pencil, Sheet, Trash2 } from 'lucide-react'; import { format } from 'date-fns'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu'; import { Skeleton } from '@/components/ui/skeleton'; import { PREVIEWABLE_MIMES } from '@/lib/constants/file-validation'; export interface FileRow { id: string; filename: string; originalName: string; mimeType: string | null; sizeBytes: string | null; storagePath?: string; category: string | null; createdAt: string | Date; uploadedBy: string; } interface FileGridProps { files: FileRow[]; onDownload: (file: FileRow) => void; onPreview: (file: FileRow) => void; onRename: (file: FileRow) => void; onDelete: (file: FileRow) => void; isLoading?: boolean; } function formatBytes(bytes: string | null): string { if (!bytes) return ''; const n = Number(bytes); if (n < 1024) return `${n} B`; if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)} KB`; return `${(n / (1024 * 1024)).toFixed(1)} MB`; } function FileIcon({ mimeType }: { mimeType: string | null }) { if (!mimeType) return ; if (mimeType.startsWith('image/')) return ; if (mimeType === 'application/pdf') return ; if ( mimeType === 'application/vnd.ms-excel' || mimeType === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' || mimeType === 'text/csv' ) { return ; } if (mimeType.startsWith('video/')) return ; return ; } export function FileGrid({ files, onDownload, onPreview, onRename, onDelete, isLoading, }: FileGridProps) { if (isLoading) { return (
{Array.from({ length: 10 }).map((_, i) => ( ))}
); } if (files.length === 0) { return (

No files yet

Upload files using the zone above

); } return (
{files.map((file) => (

{file.filename}

{formatBytes(file.sizeBytes)} {format(new Date(file.createdAt), 'MMM d, yyyy')}
onDownload(file)}> Download {file.mimeType && PREVIEWABLE_MIMES.has(file.mimeType) && ( onPreview(file)}> Preview )} onRename(file)}> Rename onDelete(file)} className="text-destructive focus:text-destructive" > Delete
))}
); }