import { useState } from 'react'; import { Check, RotateCcw, X } from 'lucide-react'; import type { QuizPayload, QuizResult, ToolCallView } from '@/lib/types'; import { api } from '@/lib/api'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/cn'; import { StreamingText } from '@/components/chat/streaming-text'; export function QuizCard({ call }: { call: ToolCallView }) { const quiz = (call.payload as { quiz?: QuizPayload }).quiz; const [answers, setAnswers] = useState>({}); const [result, setResult] = useState(null); const [busy, setBusy] = useState(false); if (!quiz) return null; const submit = async () => { setBusy(true); try { setResult(await api(`/quiz/${quiz.quiz_id}/answers`, { method: 'POST', body: JSON.stringify({ answers }) })); } finally { setBusy(false); } }; const reset = () => { setAnswers({}); setResult(null); }; const res = (id: string) => result?.results.find((r) => r.id === id); const answered = quiz.questions.every((q) => answers[q.id] !== undefined && answers[q.id] !== ''); return (
{quiz.title}
{quiz.course} · {quiz.questions.length} questions · {quiz.difficulty}
{result && (
= 0.7 ? 'bg-[#e9f6d9] text-[#3f7a0a]' : 'bg-amber-50 text-amber-700')}> {result.correct}/{result.total} · {Math.round(result.score * 100)} %
)}
    {quiz.questions.map((q, i) => { const r = res(q.id); return (
  1. {i + 1}.
    {r && (r.correct ? : )}
    {q.type === 'mcq' && q.choices?.map((c, idx) => ( ))} {q.type === 'true_false' && (
    {[true, false].map((v) => ( ))}
    )} {q.type === 'numeric' && (
    setAnswers((a) => ({ ...a, [q.id]: e.target.value }))} className="h-11 w-44 rounded-xl border border-neutral-line px-3 text-sm" /> {q.unit && {q.unit}} {r && !r.correct && Réponse : {String(r.answer)} {r.unit}}
    )} {r && r.explanation &&
    }
  2. ); })}
{!result ? ( ) : ( )}
); }