import type { ColumnDef } from '@tanstack/react-table'; import { Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/data-display'; export type CashAccount = { id: number; name: string; balance: number; formatted_balance: string; }; type CreateColumnsParams = { handleEdit: (cashAccount: CashAccount) => void; handleDeleteClick: (cashAccount: CashAccount) => void; can: (permission: string) => boolean; }; export function createCashAccountColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, can } = params; const columns: ColumnDef[] = [ { accessorKey: 'name', header: () => Nama, cell: ({ row }) => ( {row.getValue('name') as string} ), }, { accessorKey: 'formatted_balance', header: () => Saldo, cell: ({ row }) => ( {row.getValue('formatted_balance') as string} ), }, ]; if (can('cash.update') || can('cash.delete')) { columns.push({ id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => { const cashAccount = row.original; return ( , show: can('cash.update'), onClick: () => handleEdit(cashAccount), }, { label: 'Hapus', icon: ( ), show: can('cash.delete'), onClick: () => handleDeleteClick(cashAccount), }, ]} /> ); }, }); } return columns; }