import type { ColumnDef } from '@tanstack/react-table'; import { Pencil, Trash2 } from 'lucide-react'; import { ImagePreviewButton } from '@/components/dialogs'; import { RowActions } from '@/components/data-display'; export type Expense = { id: number; amount: number; formatted_amount: string; description: string; receipt_key: string | null; receipt_url: string | null; created_at: string; formatted_created_at: string; created_by: { user_profile: { full_name: string; }; }; }; type CreateColumnsParams = { handleEdit: (expense: Expense) => void; handleDeleteClick: (expense: Expense) => void; can: (permission: string) => boolean; }; export function createExpenseColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, can } = params; const columns: ColumnDef[] = [ { accessorKey: 'formatted_created_at', header: () => Tanggal, cell: ({ row }) => ( {row.getValue('formatted_created_at') as string} ), }, { accessorKey: 'description', header: () => Keterangan, cell: ({ row }) => ( {row.getValue('description') as string} ), }, { id: 'receipt', header: () => Bukti, cell: ({ row }) => { const receiptUrl = row.original.receipt_url; if (!receiptUrl) { return -; } return ( ); }, }, { accessorKey: 'formatted_amount', header: () => Jumlah, cell: ({ row }) => ( {row.getValue('formatted_amount') as string} ), }, { id: 'created_by', header: () => Oleh, cell: ({ row }) => { const createdBy = row.original.created_by; return {createdBy?.user_profile?.full_name ?? '-'}; }, }, ]; if (can('expenses.update') || can('expenses.delete')) { columns.push({ id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => { const expense = row.original; return ( , show: can('expenses.update'), onClick: () => handleEdit(expense), }, { label: 'Hapus', icon: ( ), show: can('expenses.delete'), onClick: () => handleDeleteClick(expense), }, ]} /> ); }, }); } return columns; }