import { type ColumnDef } from '@tanstack/react-table'; import { ArrowLeftRight, ArrowRightFromLine, Banknote, Pencil, Trash2, TrendingDown, TrendingUp } from 'lucide-react'; import { type Transaction } from '@/lib/api'; import { formatAmount } from '@/lib/format'; import { cn } from '@/lib/utils'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { DataTableColumnHeader } from '@/components/ui/data-table-column-header'; interface TransactionColumnOptions { showCategory: boolean; showSourceIcon?: boolean; onEdit: (tx: Transaction) => void; onDelete: (txId: number) => void; onToggleDeferred?: (tx: Transaction) => void; } export function getTransactionColumns({ showCategory, showSourceIcon, onEdit, onDelete, onToggleDeferred, }: TransactionColumnOptions): ColumnDef[] { const columns: ColumnDef[] = [ { accessorKey: 'date', header: ({ column }) => , cell: ({ row }) => ( {new Date(row.original.date).toLocaleDateString('en-US', { month: 'short', day: 'numeric', year: 'numeric', })} ), }, { accessorKey: 'merchant', header: ({ column }) => , cell: ({ row }) => { const tx = row.original; return (
{tx.transaction_type === 'COMPRA' ? ( ) : ( )}
{tx.merchant} {showSourceIcon && tx.source === 'CASH' && ( )} {showSourceIcon && tx.source === 'TRANSFER' && ( )} {tx.deferred_to_next_cycle && ( Diferida )}
); }, }, ]; if (showCategory) { columns.push({ accessorFn: (row) => row.category?.name ?? '', id: 'category', header: ({ column }) => , cell: ({ row }) => { const category = row.original.category; return category ? ( {category.name} ) : ( ); }, }); } columns.push( { accessorKey: 'amount', meta: { className: 'text-right' }, header: ({ column }) => ( ), cell: ({ row }) => { const tx = row.original; return ( {tx.transaction_type === 'COMPRA' ? '-' : '+'} {formatAmount(tx.amount, tx.currency)} ); }, }, { id: 'actions', meta: { className: 'text-right' }, size: 80, enableSorting: false, cell: ({ row }) => { const tx = row.original; return (
{onToggleDeferred && ( )}
); }, }, ); return columns; }