import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { CoursePlayerProps } from '@/types/page'; import { Link, usePage } from '@inertiajs/react'; import { format } from 'date-fns'; import { ClipboardList, Lock } from 'lucide-react'; import QuizResultDialog from './quiz-result-dialog'; interface Props { quiz: SectionQuiz; completed: { id: number | string; type: string }[]; } const QuizIcon = ({ quiz, latestSubmission }: { quiz: SectionQuiz; latestSubmission: QuizSubmission | null }) => { const { props } = usePage(); const { translate } = props; const { frontend } = translate; const isPassed = latestSubmission?.is_passed; const hasAttempted = latestSubmission !== null; return (
{/* Quiz-Symbol */}
{/* Quiz-Info */}

{quiz.title}

{latestSubmission && ( {isPassed ? frontend.passed : frontend.not_passed} )} {!hasAttempted && ( Nicht eingereicht )}

{format(new Date(quiz.created_at), 'PPpp')}

); }; const QuizStatus = ({ quiz, completed }: Props) => { const { props } = usePage(); const { watchHistory, translate } = props; const { frontend } = translate; const isCompleted = completed.some((item) => item.type === 'quiz' && item.id == quiz.id); const isCurrentLesson = watchHistory.current_watching_type === 'quiz' && watchHistory.current_watching_id == quiz.id; const isNext = watchHistory.next_watching_type === 'quiz' && quiz.id == watchHistory.next_watching_id; const latestSubmission = quiz.quiz_submissions && quiz.quiz_submissions.length > 0 ? quiz.quiz_submissions[quiz.quiz_submissions.length - 1] : null; const totalMarks = latestSubmission?.total_marks || 0; const hasAttempted = latestSubmission !== null; return ( <> {isCompleted || isCurrentLesson || isNext ? (
{/* Marks Display */} {hasAttempted && (

{frontend.total_marks}: {totalMarks}/{quiz.total_mark}

)} {/* Action Button */} {hasAttempted ? ( ) : ( )}
) : (
{/* Punkteanzeige */} {hasAttempted && (

{frontend.total_marks}: {totalMarks}/{quiz.total_mark}

)}
)} ); }; export default QuizStatus;