import type { ColumnDef } from '@tanstack/react-table'; import { Key, Pencil, Trash2 } from 'lucide-react'; import { ActiveStatusSwitch } from '@/components/active-status-switch'; import { GenderBadge } from '@/components/gender-badge'; import { RowActions } from '@/components/row-actions'; export type Lecturer = { id: number; username: string; email: string; is_active: boolean; profile: { full_name: string; phone_number: string; gender: string } | null; lecturer: { lecturer_number: string; departments: { id: number; name: string }[]; } | null; }; type CreateColumnsParams = { handleEdit: (lecturer: Lecturer) => void; handleDeleteClick: (lecturer: Lecturer) => void; handleResetPassword: (lecturer: Lecturer) => void; handleUserStatusChange: (lecturer: Lecturer, isActive: boolean) => void; canUpdate: boolean; canDelete: boolean; canResetPassword: boolean; canUpdateStatus: boolean; }; export function createLecturerColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, handleResetPassword, handleUserStatusChange, canUpdate, canDelete, canResetPassword, canUpdateStatus, } = params; return [ { id: 'identity', header: () => NIDN, cell: ({ row }) => (
{row.original.lecturer?.lecturer_number ?? '-'} {row.original.profile?.full_name ?? '-'}
), }, { id: 'account', header: () => Akun, cell: ({ row }) => (
{row.original.username} {row.original.email}
), }, { id: 'departments', header: () => Jurusan, cell: ({ row }) => { const departments = row.original.lecturer?.departments ?? []; return departments.length > 0 ? departments .map((department) => department.name) .join(', ') : '-'; }, }, { accessorKey: 'profile.phone_number', header: () => Nomor Telepon, cell: ({ row }) => row.original.profile?.phone_number ?? '-', }, { accessorKey: 'profile.gender', header: () => Jenis Kelamin, cell: ({ row }) => ( ), }, { accessorKey: 'is_active', header: () => Status Akun, cell: ({ row }) => ( handleUserStatusChange(row.original, isActive) } disabled={!canUpdateStatus} /> ), }, { id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => { const lecturer = row.original; return ( , show: canUpdate, onClick: () => handleEdit(lecturer), }, { label: 'Reset Kata Sandi', icon: , show: canResetPassword, onClick: () => handleResetPassword(lecturer), }, { label: 'Hapus', icon: ( ), show: canDelete, onClick: () => handleDeleteClick(lecturer), }, ]} /> ); }, }, ]; }