"use client" import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table" import { Button } from "@/components/ui/button" import { Badge } from "@/components/ui/badge" import { Checkbox } from "@/components/ui/checkbox" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger, DropdownMenuSeparator, } from "@/components/ui/dropdown-menu" import { FileIcon, Download, Trash2, MoreVertical, FileText, Image as ImageIcon, Box, FileJson, Settings, Mail, Globe, Archive, ExternalLink, } from "lucide-react" import type { FileItem } from "@/lib/types/file-manager.types" import { formatBytes } from "@/lib/utils" import { formatDistanceToNow } from "date-fns" import { hu } from "date-fns/locale" import { cn } from "@/lib/utils" import { deleteFile } from "@/lib/actions/file-manager.actions" import { toast } from "sonner" import { useRouter } from "next/navigation" interface FileListProps { files: FileItem[] selectedFiles: string[] onSelectFiles: (fileIds: string[]) => void onFileClick: (fileId: string) => void } export function FileList({ files, selectedFiles, onSelectFiles, onFileClick }: FileListProps) { const router = useRouter() const handleSelectAll = (checked: boolean) => { if (checked) { onSelectFiles(files.map((f) => f.id)) } else { onSelectFiles([]) } } const handleSelectFile = (fileId: string, checked: boolean) => { if (checked) { onSelectFiles([...selectedFiles, fileId]) } else { onSelectFiles(selectedFiles.filter((id) => id !== fileId)) } } const handleDelete = async (fileId: string) => { if (!confirm("Are you sure you want to delete this file?")) return try { await deleteFile(fileId) toast.success("File deleted successfully") router.refresh() } catch (error: any) { toast.error(error.message || "Failed to delete file") } } const getFileIcon = (type: FileItem["type"]) => { const icons = { model: Box, image: ImageIcon, document: FileText, data: FileJson, config: Settings, template: Mail, translation: Globe, archive: Archive, other: FileIcon, } return icons[type] || FileIcon } if (files.length === 0) { return (

No files found

) } return (
0} onCheckedChange={handleSelectAll} /> Name Type Category Size Uploaded Status {files.map((file) => { const Icon = getFileIcon(file.type) return ( onFileClick(file.id)} > e.stopPropagation()}> handleSelectFile(file.id, checked as boolean)} />
{file.name}
{file.modelMetadata && (
{file.modelMetadata.triangles.toLocaleString()} triangles
)}
{file.extension.replace(".", "").toUpperCase()} {file.category} {formatBytes(file.size)} {formatDistanceToNow(new Date(file.uploadedAt), { addSuffix: true, locale: hu })} {file.linkedTo && file.linkedTo.length > 0 ? ( In Use ({file.linkedTo.length}) ) : ( Unused )} e.stopPropagation()}> window.open(file.storageUrl, "_blank")}> Open in New Tab { const a = document.createElement("a") a.href = file.storageUrl a.download = file.name a.click() }}> Download { navigator.clipboard.writeText(file.storageUrl) toast.success("URL copied!") }}> Copy URL handleDelete(file.id)} className="text-destructive" disabled={file.linkedTo && file.linkedTo.length > 0} > Delete
) })}
) }