"use client"; import { type ColumnDef } from "@tanstack/react-table"; import { FileArchive, Eye } from "lucide-react"; import { DataTableColumnHeader } from "@/components/shared/data-table-column-header"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { SendToTelegramButton } from "./send-to-telegram-button"; export interface PackageRow { id: string; fileName: string; fileSize: string; contentHash: string; archiveType: "ZIP" | "RAR" | "SEVEN_Z" | "DOCUMENT"; fileCount: number; isMultipart: boolean; hasPreview: boolean; creator: string | null; tags: string[]; indexedAt: string; sourceChannel: { id: string; title: string; }; matchedFileCount: number; matchedByContent: boolean; } interface PackageColumnsProps { onViewFiles: (pkg: PackageRow) => void; onSetCreator: (pkg: PackageRow) => void; onSetTags: (pkg: PackageRow) => void; searchTerm: string; } function formatBytes(bytesStr: string): string { const bytes = Number(bytesStr); if (bytes === 0) return "0 B"; const k = 1024; const sizes = ["B", "KB", "MB", "GB", "TB"]; const i = Math.floor(Math.log(bytes) / Math.log(k)); return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`; } function PreviewCell({ pkg }: { pkg: PackageRow }) { if (pkg.hasPreview) { return ( ); } return (
); } export function getPackageColumns({ onViewFiles, onSetCreator, onSetTags, searchTerm, }: PackageColumnsProps): ColumnDef[] { return [ { id: "preview", header: "", cell: ({ row }) => , enableHiding: false, enableSorting: false, size: 52, }, { accessorKey: "fileName", header: ({ column }) => , cell: ({ row }) => (
{row.original.fileName} {row.original.isMultipart && ( Multi )}
{searchTerm && row.original.matchedByContent && ( )}
), enableHiding: false, }, { accessorKey: "archiveType", header: ({ column }) => , cell: ({ row }) => ( {row.original.archiveType} ), }, { accessorKey: "fileSize", header: ({ column }) => , cell: ({ row }) => ( {formatBytes(row.original.fileSize)} ), }, { accessorKey: "fileCount", header: ({ column }) => , cell: ({ row }) => ( {row.original.fileCount.toLocaleString()} ), }, { accessorKey: "creator", header: ({ column }) => , cell: ({ row }) => ( ), }, { id: "tags", header: ({ column }) => , cell: ({ row }) => { const tags = row.original.tags; if (tags.length === 0) { return ( ); } return ( ); }, accessorFn: (row) => row.tags.join(", "), }, { id: "channel", header: ({ column }) => , cell: ({ row }) => ( {row.original.sourceChannel.title} ), accessorFn: (row) => row.sourceChannel.title, }, { accessorKey: "indexedAt", header: ({ column }) => , cell: ({ row }) => ( {new Date(row.original.indexedAt).toLocaleDateString()} ), }, { id: "actions", cell: ({ row }) => (
), enableHiding: false, }, ]; }