"use client" import { dataGridFeatures, type DataGridFeatures } from "@/components/reui/data-grid" import { useMemo } from "react" import { type ColumnDef, useTable, } from "@tanstack/react-table" import { cn } from "@/lib/utils" 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 { RouteIcon } from "lucide-react" export interface OspfRouteRow { id: string dataUnknown?: boolean destination: string type: "O" | "O IA" | "O E1" | "O E2" | "Unknown" cost: number | null nextHop: string via: string serverId: string serverLabel: string area: string } function routeTypeClass(type: OspfRouteRow["type"]) { if (type === "Unknown") return "bg-muted text-muted-foreground border-border" if (type === "O") return "bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-500/25" if (type === "O IA") return "bg-blue-500/10 text-blue-600 dark:text-blue-400 border-blue-500/25" if (type === "O E1") return "bg-purple-500/10 text-purple-600 dark:text-purple-400 border-purple-500/25" return "bg-orange-500/10 text-orange-600 dark:text-orange-400 border-orange-500/25" } interface OspfRoutesDataGridProps { emptyTitle?: string routes: OspfRouteRow[] } function OspfRoutesDataGrid({ routes, emptyTitle }: OspfRoutesDataGridProps) { const columns = useMemo[]>( () => [ { id: "destination", accessorKey: "destination", header: ({ column }) => ( ), cell: ({ row }) => {row.original.destination}, meta: { headerTitle: "Назначение", headerClassName: DATA_GRID_CELL_PAD_FIRST, cellClassName: DATA_GRID_CELL_PAD_FIRST, }, }, { id: "type", accessorKey: "type", header: ({ column }) => , cell: ({ row }) => ( {row.original.type === "Unknown" ? "Тип неизвестен" : row.original.type} ), meta: { headerTitle: "Тип", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "cost", accessorKey: "cost", header: ({ column }) => , cell: ({ row }) => ( {row.original.cost ?? "—"} ), meta: { headerTitle: "Cost", headerClassName: DATA_GRID_CELL_PAD, cellClassName: cn(DATA_GRID_CELL_PAD, "text-center"), }, }, { id: "nextHop", accessorKey: "nextHop", header: ({ column }) => , cell: ({ row }) => ( {row.original.nextHop} ), meta: { headerTitle: "Следующий хоп", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "via", accessorKey: "via", header: ({ column }) => , cell: ({ row }) => ( {row.original.via} ), meta: { headerTitle: "Интерфейс", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "serverLabel", accessorKey: "serverLabel", header: ({ column }) => , cell: ({ row }) => {row.original.serverLabel}{row.original.dataUnknown ? " · Неизвестно" : ""}, meta: { headerTitle: "Роутер", headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD, }, }, { id: "area", accessorKey: "area", header: ({ column }) => , cell: ({ row }) => ( {row.original.area} ), meta: { headerTitle: "Область", headerClassName: DATA_GRID_CELL_PAD_LAST, cellClassName: DATA_GRID_CELL_PAD_LAST, }, }, ], [], ) const table = useTable({ features: dataGridFeatures, manualPagination: true, data: routes, columns, getRowId: (row) => row.id, }) if (routes.length === 0) { return ( } title={emptyTitle ?? "Нет OSPF-маршрутов"} className="border-0 py-10" /> ) } return ( ) } export { OspfRoutesDataGrid, type OspfRoutesDataGridProps, routeTypeClass }