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