"use client" import { useMemo } from "react" import { type ColumnDef, getCoreRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table" import type { GrePool } from "@/lib/data" import { cn } from "@/lib/utils" import { Button } from "@/components/ui/button" import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" 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 { LayersIcon, MoreHorizontalIcon, PencilIcon, Trash2Icon } from "lucide-react" interface GrePoolsDataGridProps { pools: GrePool[] } function GrePoolsDataGrid({ pools }: GrePoolsDataGridProps) { const columns = useMemo[]>( () => [ { id: "name", accessorKey: "name", header: ({ column }) => ( ), cell: ({ row }) => ( {row.original.name} ), meta: { headerTitle: "Имя пула", headerClassName: DATA_GRID_CELL_PAD_FIRST, cellClassName: DATA_GRID_CELL_PAD_FIRST, }, }, { id: "cidr", accessorKey: "cidr", header: ({ column }) => , cell: ({ row }) => {row.original.cidr}, meta: { headerTitle: "Диапазон CIDR", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "allocated", accessorKey: "allocated", header: ({ column }) => ( ), cell: ({ row }) => ( {row.original.allocated} ), meta: { headerTitle: "Назначено /30", headerClassName: cn(DATA_GRID_CELL_PAD, "text-right"), cellClassName: cn(DATA_GRID_CELL_PAD, "text-right"), }, }, { id: "available", header: () => ( Доступно /30 ), enableSorting: false, cell: ({ row }) => { const p = row.original return ( {p.total - p.allocated} ) }, meta: { headerClassName: cn(DATA_GRID_CELL_PAD, "text-right"), cellClassName: cn(DATA_GRID_CELL_PAD, "text-right"), }, }, { id: "usage", header: () => Использование, enableSorting: false, cell: ({ row }) => { const pool = row.original const pct = pool.total > 0 ? Math.round((pool.allocated / pool.total) * 100) : 0 return (
80 ? "bg-amber-500" : "bg-emerald-500")} style={{ width: `${pct}%` }} />
{pct}%
) }, meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "comment", accessorKey: "comment", header: ({ column }) => , cell: ({ row }) => ( {row.original.comment} ), meta: { headerTitle: "Назначение", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "actions", header: () => Действия, enableSorting: false, cell: () => (
} /> Редактировать Удалить пул
), size: 56, meta: { headerClassName: DATA_GRID_CELL_PAD_LAST, cellClassName: DATA_GRID_CELL_PAD_LAST }, }, ], [], ) const table = useReactTable({ data: pools, columns, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getRowId: (row) => row.id, }) if (pools.length === 0) { return ( } title="Нет IP-пулов" className="border-0 py-16" /> ) } return ( ) } export { GrePoolsDataGrid, type GrePoolsDataGridProps }