"use client" import { useMemo, type ReactNode } from "react" import { type ColumnDef, getCoreRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table" import type { Backup } from "@/lib/data" import { Button } from "@/components/ui/button" import { Badge } from "@/components/reui/badge" import { IconTile } from "@/components/reui/icon-tile" 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 { CloudIcon, DownloadIcon, HardDriveIcon, RefreshCwIcon, Trash2Icon, } from "lucide-react" interface BackupsDataGridProps { backups: Backup[] onDownload: (id: string, filename: string) => void onRestore: (backup: Backup) => void onDelete: (backup: Backup) => void emptyAction?: ReactNode emptyTitle?: string emptyDescription?: string } function storageBadge(storage: Backup["storage"]) { if (storage === "s3") return { label: "S3", variant: "info-light" as const } if (storage === "both") return { label: "Локально + S3", variant: "success-light" as const } return { label: "Локально", variant: "secondary" as const } } function BackupsDataGrid({ backups, onDownload, onRestore, onDelete, emptyAction, emptyTitle = "Нет бэкапов", emptyDescription = "Создайте первый бэкап вручную или настройте расписание", }: BackupsDataGridProps) { const columns = useMemo[]>( () => [ { id: "filename", accessorKey: "filename", header: ({ column }) => , cell: ({ row }) => { const b = row.original const inS3 = b.storage === "s3" || b.storage === "both" return (
{b.filename} {b.uploadError ? ( {b.uploadError} ) : null}
) }, 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 }) => ( {row.original.kind === "auto" ? "авто" : "вручную"} ), meta: { headerTitle: "Тип", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "storage", accessorKey: "storage", header: ({ column }) => , cell: ({ row }) => { const badge = storageBadge(row.original.storage) return ( {badge.label} ) }, 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={emptyTitle} description={emptyDescription} action={emptyAction} className="border-0 py-10" /> ) } return } export { BackupsDataGrid, type BackupsDataGridProps }