"use client" import { useMemo, type ReactNode } from "react" import { type ColumnDef, getCoreRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table" import type { IpsecClientDto } from "@mmapp/contracts/ipsec" import { cn } from "@/lib/utils" import { Badge } from "@/components/ui/badge" 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 { BadgeCheckIcon, KeyRoundIcon, Trash2Icon, UsersIcon, WifiIcon, } from "lucide-react" export interface IpsecUsersGridProps { clients: IpsecClientDto[] compactServer?: boolean emptyAction?: ReactNode onDownloadCert?: (row: IpsecClientDto) => void onEdit?: (row: IpsecClientDto) => void onDelete?: (row: IpsecClientDto) => void } function IpsecUsersGrid({ clients, compactServer = false, emptyAction, onDownloadCert, onEdit, onDelete, }: IpsecUsersGridProps) { const columns = useMemo[]>(() => { const cols: ColumnDef[] = [ { id: "name", accessorKey: "name", header: ({ column }) => ( ), cell: ({ row }) => { const c = row.original return (
{c.disabled ? ( выкл ) : null} {!c.managed ? ( RouterOS ) : null}
) }, meta: { headerTitle: "Клиент", headerClassName: DATA_GRID_CELL_PAD_FIRST, cellClassName: DATA_GRID_CELL_PAD_FIRST, }, }, { id: "auth", accessorKey: "authMethod", header: ({ column }) => , cell: ({ row }) => { const cert = row.original.authMethod === "certificate" return (
{cert ? ( ) : ( )} {cert ? "Сертификат" : "PSK"}
) }, meta: { headerTitle: "Аутентификация", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, ] if (!compactServer) { cols.push({ id: "server", accessorKey: "serverName", header: ({ column }) => , cell: ({ row }) => ( {row.original.serverName} ), meta: { headerTitle: "Сервер", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }) } cols.push( { id: "ip", accessorFn: (row) => row.staticIp ?? "", header: ({ column }) => , cell: ({ row }) => ( {row.original.staticIp ?? "из пула"} ), meta: { headerTitle: "IP", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "online", accessorKey: "online", header: ({ column }) => , cell: ({ row }) => (
{row.original.online ? row.original.activeAddress ?? "онлайн" : "офлайн"}
), meta: { headerTitle: "Статус", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "actions", header: () => Действия, enableSorting: false, size: 96, cell: ({ row }) => { const c = row.original return (
{c.authMethod === "certificate" && onDownloadCert ? ( ) : null} {onDelete ? ( ) : null}
) }, meta: { headerClassName: DATA_GRID_CELL_PAD_LAST, cellClassName: DATA_GRID_CELL_PAD_LAST, }, }, ) return cols }, [compactServer, onDownloadCert, onEdit, onDelete]) const table = useReactTable({ data: clients, columns, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getRowId: (row) => row.id, }) if (clients.length === 0) { return ( } title="Нет клиентов IKEv2" description="Создайте клиента — сертификат и .p12 выпустятся автоматически" action={emptyAction} className="border-0 py-16" /> ) } return ( ) } export { IpsecUsersGrid }