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'; import { StatusBadge } from '@/components/status-badge'; const StudentStatusVariants: Record< string, 'default' | 'secondary' | 'destructive' | 'outline' > = { active: 'default', on_leave: 'secondary', graduated: 'outline', dropped_out: 'destructive', }; export type Student = { id: number; username: string; email: string; is_active: boolean; profile: { full_name: string; phone_number: string; gender: string } | null; student: { student_number: string; department: { name: string } | null; enrollment_year: number; current_semester: number; status: string | null; } | null; }; type StatusOption = { value: string; label: string }; type CreateColumnsParams = { handleEdit: (student: Student) => void; handleDeleteClick: (student: Student) => void; handleResetPassword: (student: Student) => void; handleStatusChange: (student: Student, status: string) => void; handleUserStatusChange: (student: Student, isActive: boolean) => void; statuses: StatusOption[]; canUpdate: boolean; canDelete: boolean; canResetPassword: boolean; canUpdateAcademicStatus: boolean; canUpdateAccountStatus: boolean; }; export function createStudentColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, handleResetPassword, handleStatusChange, handleUserStatusChange, statuses, canUpdate, canDelete, canResetPassword, canUpdateAcademicStatus, canUpdateAccountStatus, } = params; const columns: ColumnDef[] = [ { id: 'identity', header: () => NIM, cell: ({ row }) => (
{row.original.student?.student_number ?? '-'} {row.original.profile?.full_name ?? '-'}
), }, { id: 'account', header: () => Akun, cell: ({ row }) => (
{row.original.username} {row.original.email}
), }, { accessorKey: 'student.department.name', header: () => Jurusan, cell: ({ row }) => row.original.student?.department?.name ?? '-', }, { accessorKey: 'student.enrollment_year', header: () => Angkatan, cell: ({ row }) => row.original.student?.enrollment_year ?? '-', }, { accessorKey: 'student.current_semester', header: () => Semester, cell: ({ row }) => row.original.student?.current_semester ?? '-', }, { accessorKey: 'student.status', header: () => Status, cell: ({ row }) => ( handleStatusChange(row.original, status) } disabled={!canUpdateAcademicStatus} /> ), }, { 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={!canUpdateAccountStatus} /> ), }, ]; if (canUpdate || canResetPassword || canDelete) { columns.push({ id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => { const student = row.original; return ( , show: canUpdate, onClick: () => handleEdit(student), }, { label: 'Reset Kata Sandi', icon: , show: canResetPassword, onClick: () => handleResetPassword(student), }, { label: 'Hapus', icon: ( ), show: canDelete, onClick: () => handleDeleteClick(student), }, ]} /> ); }, }); } return columns; }