"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