import TableHeader from '@/components/table/table-header'; import { Badge } from '@/components/ui/badge'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Table, TableBody, TableCell, TableRow } from '@/components/ui/table'; import ExamAttemptColumn from '@/pages/student/partials/exam-attempt-columns'; import { StudentExamProps } from '@/types/page'; import { usePage } from '@inertiajs/react'; import { SortingState, flexRender, getCoreRowModel, getFilteredRowModel, getSortedRowModel, useReactTable } from '@tanstack/react-table'; import { Award, Clock } from 'lucide-react'; import * as React from 'react'; const ExamAttempts = () => { const { exam, attempts, bestAttempt } = usePage().props; const [sorting, setSorting] = React.useState([]); const table = useReactTable({ data: attempts || [], columns: ExamAttemptColumn(exam?.id ?? 0, bestAttempt?.id), onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getFilteredRowModel: getFilteredRowModel(), state: { sorting }, }); if (!attempts || attempts.length === 0) { return (

No attempts yet

Your exam attempts will appear here once you start the exam.

); } return (
{/* Exam Attempts Summary */}

Total Attempts

{attempts.length}

Completed

{attempts.filter((a: ExamAttempt) => a.status === 'completed').length}

In Progress

{attempts.filter((a: ExamAttempt) => a.status === 'in_progress').length}

Best Score

{bestAttempt?.obtained_marks}

{bestAttempt && }
{/* Attempts Table */} Exam Attempts {bestAttempt && ( Best Score {bestAttempt.obtained_marks} )} {table.getRowModel().rows?.length ? ( table.getRowModel().rows.map((row) => ( {row.getVisibleCells().map((cell) => ( {flexRender(cell.column.columnDef.cell, cell.getContext())} ))} )) ) : ( No exam attempts found. )}
); }; export default ExamAttempts;