import { Card, CardContent, CardHeader } from '@/components/ui/card'; import { cn } from '@/lib/utils'; import { Link } from '@inertiajs/react'; import ButtonGradientPrimary from '../button-gradient-primary'; import { Avatar, AvatarFallback, AvatarImage } from '../ui/avatar'; import { Badge } from '../ui/badge'; import { Progress } from '../ui/progress'; interface Props { exam: Exam; attempts: ExamAttempt[]; bestAttempt: ExamAttempt | null; className?: string; } const ExamCard7 = ({ exam, attempts, bestAttempt, className }: Props) => { // Calculate progress based on attempts const totalAttempts = attempts?.length || 0; const completedAttempts = attempts?.filter((a) => a.status === 'completed').length || 0; const progress = exam.max_attempts > 0 ? (totalAttempts / exam.max_attempts) * 100 : 0; const progressPercentage = Math.min(progress, 100); // Get best score percentage const bestScore = bestAttempt && Number(bestAttempt.total_marks) > 0 ? Math.round((Number(bestAttempt.obtained_marks) / Number(bestAttempt.total_marks)) * 100 * 100) / 100 : 0; return ( {exam.title} { const target = e.target as HTMLImageElement; target.src = '/assets/images/blank-image.jpg'; }} />
IM

{exam.instructor?.user?.name || 'Instructor'}

{exam.title}

Attempts {totalAttempts} / {exam.max_attempts}

Best Score {bestAttempt?.obtained_marks ?? 0} / {bestAttempt?.total_marks ?? 0} ({bestScore}%)

{bestAttempt && (
{bestAttempt.is_passed ? Passed : Failed} Pass Mark: {exam.pass_mark}%
)}
{totalAttempts < exam.max_attempts && ( Start Exam )}
); }; export default ExamCard7;