"use client" import { useMemo } from "react" import { type ColumnDef, getCoreRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table" import type { Backup } from "@/lib/data" import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { DataGridShell } from "@/components/data-grids/shared/data-grid-shell" import { DATA_GRID_CELL_PAD, DATA_GRID_CELL_PAD_FIRST, DATA_GRID_CELL_PAD_LAST, } from "@/components/data-grids/shared/data-grid-layout" import { DataGridSortHeader } from "@/components/data-grids/shared/data-grid-sort-header" import { EmptyState } from "@/components/empty-state" import { DownloadIcon, HardDriveIcon, RefreshCwIcon, Trash2Icon } from "lucide-react" interface BackupsDataGridProps { backups: Backup[] onDownload: (id: string, filename: string) => void onRestore: (backup: Backup) => void onDelete: (id: string) => void } function BackupsDataGrid({ backups, onDownload, onRestore, onDelete, }: BackupsDataGridProps) { const columns = useMemo[]>( () => [ { id: "filename", accessorKey: "filename", header: ({ column }) => , cell: ({ row }) => ( {row.original.filename} ), meta: { headerTitle: "Файл", headerClassName: DATA_GRID_CELL_PAD_FIRST, cellClassName: DATA_GRID_CELL_PAD_FIRST, }, }, { id: "server", accessorKey: "server", header: ({ column }) => , cell: ({ row }) => ( {row.original.server} ), meta: { headerTitle: "Сервер", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "size", accessorKey: "size", header: ({ column }) => , cell: ({ row }) => ( {row.original.size} ), meta: { headerTitle: "Размер", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "kind", accessorKey: "kind", header: ({ column }) => , cell: ({ row }) => { const kind = row.original.kind return ( {kind === "auto" ? "авто" : "вручную"} ) }, meta: { headerTitle: "Тип", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "notes", accessorKey: "notes", header: ({ column }) => , cell: ({ row }) => ( {row.original.notes || "—"} ), meta: { headerTitle: "Заметки", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "created", accessorKey: "created", header: ({ column }) => , cell: ({ row }) => ( {row.original.created} ), meta: { headerTitle: "Создан", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "actions", header: () => Действия, cell: ({ row }) => { const b = row.original return (
) }, enableSorting: false, size: 120, meta: { headerClassName: DATA_GRID_CELL_PAD_LAST, cellClassName: DATA_GRID_CELL_PAD_LAST, }, }, ], [onDelete, onDownload, onRestore], ) const table = useReactTable({ data: backups, columns, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getRowId: (row) => row.id, }) if (backups.length === 0) { return ( } title="Нет бэкапов" description="Создайте первый бэкап вручную или настройте расписание" className="border-0 py-10" /> ) } return } export { BackupsDataGrid, type BackupsDataGridProps }