"use client" import { useMemo } from "react" import { type ColumnDef, getCoreRowModel, getSortedRowModel, useReactTable, } from "@tanstack/react-table" import type { Server } from "@/lib/data" import { Flag } from "@/components/flag" import { cn } from "@/lib/utils" import { FormToggle } from "@/components/form-kit" 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 { CableIcon, CopyIcon, EyeIcon, EyeOffIcon, Trash2Icon } from "lucide-react" export interface SubUserRow { id: string login: string password: string description: string jhServerIds: string[] clientIp: string active: boolean lastSeen: string | null } interface SubusersDataGridProps { subUsers: SubUserRow[] servers: Server[] revealedIds: Set onToggleReveal: (id: string) => void onToggleActive: (id: string) => void onRemove: (id: string) => void } function SubusersDataGrid({ subUsers, servers, revealedIds, onToggleReveal, onToggleActive, onRemove, }: SubusersDataGridProps) { const columns = useMemo[]>( () => [ { id: "login", accessorKey: "login", header: ({ column }) => ( ), cell: ({ row }) => { const su = row.original return (

{su.login}

{su.description && (

{su.description}

)} {su.lastSeen && (

{su.lastSeen}

)}
) }, meta: { headerTitle: "Логин / описание", headerClassName: DATA_GRID_CELL_PAD_FIRST, cellClassName: DATA_GRID_CELL_PAD_FIRST, }, }, { id: "password", header: () => Пароль, enableSorting: false, cell: ({ row }) => { const su = row.original const revealed = revealedIds.has(su.id) return (
e.stopPropagation()}> {revealed ? su.password : "••••••••••••"}
) }, meta: { headerTitle: "Пароль", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "jhServers", header: () => JH-серверы, enableSorting: false, cell: ({ row }) => { const jhs = servers.filter((s) => row.original.jhServerIds.includes(s.id)) return (
{jhs.length === 0 ? ( ) : ( jhs.map((jh) => ( {jh.name.split("-").slice(-1)[0]} )) )}
) }, meta: { headerTitle: "JH-серверы", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "clientIp", accessorKey: "clientIp", header: ({ column }) => , cell: ({ row }) => ( {row.original.clientIp || "—"} ), meta: { headerTitle: "IP-клиента", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "active", accessorKey: "active", header: () => Активен, enableSorting: false, cell: ({ row }) => (
e.stopPropagation()}> onToggleActive(row.original.id)} />
), size: 48, meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "actions", header: () => Удалить, enableSorting: false, cell: ({ row }) => ( ), size: 40, meta: { headerClassName: DATA_GRID_CELL_PAD_LAST, cellClassName: DATA_GRID_CELL_PAD_LAST, }, }, ], [onRemove, onToggleActive, onToggleReveal, revealedIds, servers], ) const table = useReactTable({ data: subUsers, columns, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getRowId: (row) => row.id, }) if (subUsers.length === 0) { return ( } title="Нет GRE-клиентов" description="Добавьте учётки для подключения устройств" className="border-0 py-12" /> ) } return ( ) } export { SubusersDataGrid, type SubusersDataGridProps }