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