import type { ColumnDef } from '@tanstack/react-table'; import { format } from 'date-fns'; import { Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/row-actions'; import { Badge } from '@/components/ui/badge'; import type { CourseRegistration, RegistrationStatus, } from '@/types/course-registration'; import { RegistrationStatusLabels } from '@/types/course-registration'; export type { CourseRegistration } from '@/types/course-registration'; type CreateColumnsParams = { handleEdit: (registration: CourseRegistration) => void; handleDeleteClick: (registration: CourseRegistration) => void; }; export function createCourseRegistrationColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick } = params; return [ { accessorKey: 'student.student_number', header: () => Mahasiswa, cell: ({ row }) => { const student = row.original.student; return (

{student?.user?.profile?.full_name ?? 'N/A'}

{student?.student_number} ·{' '} {student?.department?.name ?? '-'}

); }, }, { accessorKey: 'course_class.course.name', header: () => Kelas Mata Kuliah, cell: ({ row }) => { const courseClass = row.original.course_class; return (

{courseClass?.course?.name ?? 'N/A'}

{courseClass?.course?.code} {courseClass?.class_name ? ` ยท ${courseClass.class_name}` : ''}

); }, }, { accessorKey: 'academic_term.name', header: () => Periode, cell: ({ row }) => row.original.academic_term?.name ?? '-', }, { accessorKey: 'status', header: () => Status, meta: { className: 'w-[130px] text-center', headerClassName: 'w-[130px] text-center', }, cell: ({ row }) => { const status = row.getValue( 'status', ) as RegistrationStatus | null; const variant = status === 'approved' ? 'default' : status === 'rejected' ? 'destructive' : 'outline'; return (
{status ? ( {RegistrationStatusLabels[status]} ) : ( - )}
); }, }, { accessorKey: 'approver.user.profile.full_name', header: () => Disetujui Oleh, cell: ({ row }) => row.original.approver?.user?.profile?.full_name ?? '-', }, { accessorKey: 'created_at', header: () => Diajukan, cell: ({ row }) => format(new Date(row.original.created_at), 'd MMM yyyy, HH:mm'), }, { id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => ( , onClick: () => handleEdit(row.original), }, { label: 'Hapus', icon: ( ), onClick: () => handleDeleteClick(row.original), }, ]} /> ), }, ]; }