import type { ColumnDef } from '@tanstack/vue-table'; import { h } from 'vue'; import DataTableActions from '@/components/admin/finance/cash/data-table-actions.vue'; import { DataTableColumnHeader } from '@/components/data-table'; import { Badge } from '@/components/ui/badge'; import type { CashTransactionListItem } from '@/types/cash'; export function createColumns(onEdit: (transaction: CashTransactionListItem) => void): ColumnDef[] { return [ { accessorKey: 'created_at_formatted', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Tanggal', column: 'created_at' }), }, { accessorKey: 'reference_label', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Sumber', column: 'reference_type' }), cell: ({ row }) => { const isIncoming = row.original.is_incoming; return h( Badge, { variant: isIncoming ? 'default' : 'secondary' }, () => row.original.reference_label, ); }, }, { accessorKey: 'amount_formatted', enableSorting: true, header: () => h(DataTableColumnHeader, { title: 'Jumlah', column: 'amount' }), cell: ({ row }) => { const isIncoming = row.original.is_incoming; const prefix = isIncoming ? '+' : '-'; return h( 'span', { class: isIncoming ? 'font-medium text-green-600' : 'font-medium text-red-600' }, `${prefix} ${row.original.amount_formatted}`, ); }, }, { accessorKey: 'balance_after_formatted', enableSorting: false, header: () => 'Saldo Setelah', }, { accessorKey: 'description', enableSorting: false, header: () => 'Keterangan', }, { accessorKey: 'created_by_name', enableSorting: false, header: () => 'Oleh', }, { id: 'actions', enableSorting: false, enableHiding: false, cell: ({ row }) => { if (row.original.reference_type !== null) { return null; } return h(DataTableActions, { transaction: row.original, onEdit: () => onEdit(row.original), }); }, }, ]; }