import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; import { getQueryParams } from '@/lib/route'; import { cn } from '@/lib/utils'; import { Link, router, usePage } from '@inertiajs/react'; import { ColumnDef } from '@tanstack/react-table'; import { ChevronsUpDown } from 'lucide-react'; import { useState } from 'react'; const ExamAttemptTableColumn = (): ColumnDef[] => { const page = usePage(); const urlParams = getQueryParams(page.url); const statuses = ['all', 'in_progress', 'completed', 'abandoned', 'submitted']; const [reviewAttemptId, setReviewAttemptId] = useState(null); const handleReviewClick = (attemptId: string | number) => { setReviewAttemptId(attemptId); }; const handleResultClick = (attemptId: string | number) => { router.get(`/exam-attempts/${attemptId}/result`); }; return [ // { // accessorKey: 'attempt_number', // header: ({ column }) => { // return ( //
// //
// ); // }, // cell: ({ row }) => ( //
//

Attempt #{row.getValue('attempt_number')}

//
// ), // }, { accessorKey: 'user', header: ({ column }) => { return (
Student
); }, cell: ({ row }) => (

{row.original.user.name}

{row.original.user.email}

), }, { accessorKey: 'start_time', header: 'Started At', cell: ({ row }) => (

{new Date(row.getValue('start_time')).toLocaleDateString()}

{new Date(row.getValue('start_time')).toLocaleTimeString()}

), }, { accessorKey: 'end_time', header: 'Completed At', cell: ({ row }) => { const endTime = row.getValue('end_time') as string; return endTime ? (

{new Date(endTime).toLocaleDateString()}

{new Date(endTime).toLocaleTimeString()}

) : (
--
); }, }, // { // accessorKey: 'duration_minutes', // header: () =>
Duration
, // cell: ({ row }) => { // const duration = row.getValue('duration_minutes') as number | undefined; // return ( //
// {duration ? ( // // {Math.floor(duration / 60)}h {duration % 60}m // // ) : ( // '--' // )} //
// ); // }, // }, { accessorKey: 'status', header: ({ column }) => (
{statuses.map((status) => ( router.get( route('exams.edit', { ...urlParams, status: status, }), ) } className={cn('cursor-pointer text-center capitalize', urlParams['status'] === status && 'bg-gray-100')} > {status.replace('_', ' ')} ))}
), cell: ({ row }) => { const status = row.getValue('status') as string; const variant = status === 'completed' ? 'default' : status === 'in_progress' ? 'secondary' : 'destructive'; return (
{status.replace('_', ' ')}
); }, }, { accessorKey: 'obtained_marks', header: () =>
Score
, cell: ({ row }) => (

{row.getValue('obtained_marks')}/{row.original.total_marks}

{row.original.percentage}%

), }, { accessorKey: 'correct_answers', header: () =>
Answers
, cell: ({ row }) => (

{row.getValue('correct_answers')} /{' '} {row.original.incorrect_answers}

), }, // { // accessorKey: 'is_passed', // header: () =>
Result
, // cell: ({ row }) => { // const isPassed = row.getValue('is_passed') as boolean; // return ( //
// {row.original.status === 'completed' ? ( // // {isPassed ? 'Passed' : 'Failed'} // // ) : ( // -- // )} //
// ); // }, // }, { id: 'actions', header: () =>
Actions
, cell: ({ row }) => { const attempt = row.original; const isSubmitted = attempt.status === 'submitted'; const isCompleted = attempt.status === 'completed'; return (
{/* {(isCompleted || isSubmitted) && ( )} {isSubmitted && ( )} */} {/* */}
); }, }, ]; }; export default ExamAttemptTableColumn;