/* Copyright (C) 2023-2026 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import { type ColumnDef } from '@tanstack/react-table' import { Pencil, Trash2 } from 'lucide-react' import { Button } from '@/components/ui/button' import { Checkbox } from '@/components/ui/checkbox' import { DataTableColumnHeader } from '@/components/data-table' import { StatusBadge } from '@/components/status-badge' import { getModeLabel, getModeVariant, getPriceDetail, getPriceSummary, type ModelRow, } from './model-pricing-snapshots' const filterBySelectedValues = ( rowValue: unknown, filterValue: unknown ): boolean => { if (!Array.isArray(filterValue) || filterValue.length === 0) return true return filterValue.includes(String(rowValue)) } type BuildModelRatioColumnsOptions = { onDelete: (name: string) => void onEdit: (model: ModelRow) => void t: (key: string) => string } export function buildModelRatioColumns({ onDelete, onEdit, t, }: BuildModelRatioColumnsOptions): ColumnDef[] { return [ { id: 'select', header: ({ table }) => ( table.toggleAllPageRowsSelected(!!value)} aria-label={t('Select all')} className='translate-y-[2px]' /> ), cell: ({ row }) => ( row.toggleSelected(!!value)} aria-label={t('Select row')} className='translate-y-[2px]' /> ), enableSorting: false, enableHiding: false, meta: { label: t('Select') }, }, { accessorKey: 'name', header: ({ column }) => ( ), cell: ({ row }) => (
{row.getValue('name')} {row.original.billingMode === 'tiered_expr' && ( )} {row.original.hasConflict && ( )}
), enableHiding: false, }, { accessorKey: 'billingMode', header: ({ column }) => ( ), cell: ({ row }) => ( ), filterFn: (row, id, value) => filterBySelectedValues(row.getValue(id), value), meta: { label: t('Mode') }, }, { id: 'priceSummary', header: ({ column }) => ( ), cell: ({ row }) => (
{getPriceSummary(row.original, t)} {getPriceDetail(row.original, t)}
), sortingFn: (rowA, rowB) => getPriceSummary(rowA.original, t).localeCompare( getPriceSummary(rowB.original, t) ), meta: { label: t('Price summary') }, }, { id: 'actions', header: () =>
{t('Actions')}
, cell: ({ row }) => (
), enableHiding: false, }, ] }