import { Checkbox } from "@repo/shadcn-ui/components"; import type { ColumnDef } from "@tanstack/react-table"; import * as React from "react"; // Columna estable (definida una vez) const selectionCol: ColumnDef = { id: "select", header: ({ table }) => ( table.toggleAllPageRowsSelected(!!v)} aria-label="Select all" className="translate-y-[2px]" /> ), cell: ({ row }) => ( row.toggleSelected(!!v)} aria-label="Select row" className="translate-y-[2px]" /> ), enableSorting: false, enableHiding: false, size: 36, minSize: 36, maxSize: 36, }; // Función pura (sin hooks) export function withRowSelection( base: ColumnDef[], enabled: boolean ): ColumnDef[] { if (!enabled) return base; // misma referencia si está desactivado // Evita duplicar si ya viene incluida if (base.length > 0 && base[0].id === selectionCol.id) return base; return [selectionCol as ColumnDef, ...base]; } // Custom hook ergonómico export function useWithRowSelection( baseColumns: ColumnDef[], enabled: boolean ) { return React.useMemo( () => withRowSelection(baseColumns, enabled), [baseColumns, enabled] ); }