import type { ColumnDef } from '@tanstack/react-table'; import { Pencil, Trash2 } from 'lucide-react'; import { RowActions } from '@/components/row-actions'; import { Badge } from '@/components/ui/badge'; import type { Course } from '@/types/course'; export type { Course } from '@/types/course'; type CreateColumnsParams = { handleEdit: (course: Course) => void; handleDeleteClick: (course: Course) => void; canUpdate: boolean; canDelete: boolean; }; export function createCourseColumns( params: CreateColumnsParams, ): ColumnDef[] { const { handleEdit, handleDeleteClick, canUpdate, canDelete } = params; const columns: ColumnDef[] = [ { accessorKey: 'code', header: () => Kode, cell: ({ row }) => ( {row.getValue('code') as string} ), }, { accessorKey: 'name', header: () => Nama Mata Kuliah, cell: ({ row }) => {row.getValue('name') as string}, }, { accessorKey: 'department.name', header: () => Jurusan, cell: ({ row }) => row.original.department?.name ?? '-', }, { accessorKey: 'credits', header: () => SKS, meta: { className: 'w-[80px] text-center', headerClassName: 'w-[80px] text-center', }, cell: ({ row }) => (
{row.getValue('credits') as number}
), }, { accessorKey: 'semester_number', header: () => Semester, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => { const semesterNumber = row.getValue('semester_number') as number | null; return (
{semesterNumber ? ( {semesterNumber} ) : ( - )}
); }, }, ]; if (canUpdate || canDelete) { columns.push({ id: 'actions', header: () => Aksi, meta: { className: 'w-[100px] text-center', headerClassName: 'w-[100px] text-center', }, cell: ({ row }) => { const course = row.original; return ( , show: canUpdate, onClick: () => handleEdit(course), }, { label: 'Hapus', icon: ( ), show: canDelete, onClick: () => handleDeleteClick(course), }, ]} /> ); }, }); } return columns; }