"use client" import { dataGridFeatures, type DataGridFeatures } from "@/components/reui/data-grid" import { useMemo } from "react" import { type ColumnDef, useTable, } from "@tanstack/react-table" import type { CommRec } from "@/lib/route-optimizer-data" import { cn } from "@/lib/utils" 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 { ArrowRightIcon, PinIcon, RefreshCwIcon } from "lucide-react" function Chip({ children, color }: { children: React.ReactNode; color?: string }) { return ( {children} ) } function ProbChip({ prob, best }: { prob: number | null; best?: boolean }) { if (prob === null) return — return ( {prob} б. ) } interface RouteOptimizerCommRecsDataGridProps { recs: CommRec[] homeId: string pinned: Set applied: Set applying: Set onPin: (key: string) => void simulation?: boolean onApply: (community: string, homeId: string) => void } function RouteOptimizerCommRecsDataGrid({ recs, homeId, pinned, applied, applying, onPin, onApply, simulation = false, }: RouteOptimizerCommRecsDataGridProps) { const rows = useMemo( () => recs.map((r, idx) => ({ ...r, _rowKey: `${homeId}::${r.community}::${idx}` })), [homeId, recs], ) const columns = useMemo[]>( () => [ { id: "community", accessorKey: "community", header: ({ column }) => ( ), cell: ({ row }) => (
{row.original.community}
{row.original.communityName}
), meta: { headerTitle: "Community", headerClassName: DATA_GRID_CELL_PAD_FIRST, cellClassName: DATA_GRID_CELL_PAD_FIRST, }, }, { id: "current", header: () => ( Базовый расчёт (WAN → JH → Exit) ), enableSorting: false, cell: ({ row }) => { const r = row.original if (!r.current) return — return (
{r.current.wan}
) }, meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "recommended", header: () => Рекомендуемый, enableSorting: false, cell: ({ row }) => { const r = row.original const pinKey = `${homeId}::${r.community}` const isPinned = pinned.has(pinKey) if (!r.recommended) return — return (
{r.recommended.wan}
) }, meta: { headerClassName: DATA_GRID_CELL_PAD, cellClassName: DATA_GRID_CELL_PAD }, }, { id: "probability", header: () => ( Индекс (баз / рек) ), enableSorting: false, cell: ({ row }) => { const r = row.original const pinKey = `${homeId}::${r.community}` return (
/
) }, meta: { headerClassName: cn(DATA_GRID_CELL_PAD, "text-center"), cellClassName: cn(DATA_GRID_CELL_PAD, "text-center"), }, }, { id: "actions", header: () => ( Действие ), enableSorting: false, cell: ({ row }) => { const r = row.original const pinKey = `${homeId}::${r.community}` const isPinned = pinned.has(pinKey) const isApplied = simulation && applied.has(pinKey) const isApplying = simulation && applying.has(pinKey) const canApply = simulation && r.shouldSwitch && !isPinned && !isApplied return (
e.stopPropagation()}> {isPinned &&
) }, meta: { headerClassName: cn(DATA_GRID_CELL_PAD_LAST, "text-right"), cellClassName: DATA_GRID_CELL_PAD_LAST, }, }, ], [applied, applying, homeId, onApply, onPin, pinned, simulation], ) const table = useTable({ features: dataGridFeatures, manualPagination: true, data: rows, columns, getRowId: (row) => row._rowKey, }) return ( ) } export { RouteOptimizerCommRecsDataGrid, type RouteOptimizerCommRecsDataGridProps }