import { Badge } from '@/components/ui/badge'; import { ColumnDef } from '@tanstack/react-table'; import { format } from 'date-fns'; import GradeSubmissionDialog from './grade-submission-dialog'; const SubmissionsTableColumn = (translate: LanguageTranslations): ColumnDef[] => { const { table } = translate; return [ { accessorKey: 'student', header: 'Student Name', cell: ({ row }) => { const student = row.original.student; return (

{student?.name || 'N/A'}

{student?.email || ''}

); }, }, { accessorKey: 'is_late', header: () =>
Submission
, cell: ({ row }) => { const isLate = row.getValue('is_late') as boolean; return (
{isLate ? 'Late Submission' : 'On Time'}
); }, }, // { // accessorKey: 'attachment_path', // header: 'Submission', // cell: ({ row }) => { // const submission = row.original; // return ( //
// {submission.attachment_type === 'url' ? ( // // // View URL // // ) : ( // // // Download File // // )} //
// ); // }, // }, { accessorKey: 'submitted_at', header: 'Submitted At', cell: ({ row }) => { const date = row.getValue('submitted_at') as string; return (

{format(new Date(date), 'MMM dd, yyyy')}

{format(new Date(date), 'hh:mm a')}

); }, }, { accessorKey: 'status', header: () =>
Status
, cell: ({ row }) => { const status = row.getValue('status') as string; const isLate = row.original.is_late; const getVariant = () => { if (status === 'graded') return 'default'; if (isLate) return 'destructive'; return 'secondary'; }; const getLabel = () => { if (status === 'graded') return 'Graded'; if (isLate) return 'Late'; return 'Pending'; }; return (
{getLabel()}
); }, }, { accessorKey: 'marks_obtained', header: () =>
Marks
, cell: ({ row }) => { const marks = row.getValue('marks_obtained') as number; const submission = row.original; const isGraded = submission.status === 'graded'; const isLate = submission.is_late; // Determine total marks based on late submission const totalMarks = isLate ? submission.assignment?.late_total_mark || 0 : submission.assignment?.total_mark || 0; return (
{isGraded ? (

{marks} / {totalMarks}

{isLate &&

(Late: Max {submission.assignment?.late_total_mark})

}
) : (

Not Graded

Max: {totalMarks}

)}
); }, }, { id: 'actions', header: () =>
{table.action}
, cell: ({ row }) => { const submission = row.original; return (
); }, }, ]; }; export default SubmissionsTableColumn;