2026-08-22 02:18:27 +03:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { cn } from "@/lib/utils";
|
2026-08-22 03:23:11 +03:00
|
|
|
import { MessageResponse } from "@/components/ai-elements/message";
|
2026-08-22 02:18:27 +03:00
|
|
|
import type { QuestionAnswerData } from "@/src/core/question-core";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Static rendering of an answered question (tool part in `output-available`).
|
|
|
|
|
*
|
|
|
|
|
* Quiz answers are GRADED: ✓/✗ marks, the correct answers, and the
|
|
|
|
|
* explanation. Ask answers are NOT graded — a plain record of what was said.
|
|
|
|
|
* (The v1 bug this pins: ask answers must never get quiz grading UI.)
|
|
|
|
|
*/
|
|
|
|
|
export function AnsweredCard({ answer }: { answer: QuestionAnswerData }) {
|
|
|
|
|
if (answer.dismissed) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="rounded-xl border bg-card p-4 text-sm text-muted-foreground">
|
|
|
|
|
<span className="font-medium">{answer.questionText}</span> — skipped
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isQuiz = answer.kind === "quiz";
|
|
|
|
|
const selectedIdx = new Set(answer.answers.map((a) => a.index));
|
|
|
|
|
const correctIdx = new Set(answer.correctIndices ?? []);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="rounded-xl border bg-card p-4 text-card-foreground" data-testid="answered-card">
|
|
|
|
|
<div className="mb-1 flex items-center gap-2 text-xs font-medium uppercase tracking-wide text-muted-foreground">
|
|
|
|
|
{isQuiz ? "Quiz" : "Question"}
|
|
|
|
|
{isQuiz &&
|
|
|
|
|
(answer.dontKnow ? (
|
|
|
|
|
<span className="rounded bg-muted px-1.5 py-0.5">didn't know</span>
|
|
|
|
|
) : answer.correct ? (
|
|
|
|
|
<span className="rounded bg-green-500/15 px-1.5 py-0.5 text-green-500">correct</span>
|
|
|
|
|
) : (
|
|
|
|
|
<span className="rounded bg-red-500/15 px-1.5 py-0.5 text-red-500">incorrect</span>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
2026-08-22 03:23:11 +03:00
|
|
|
<div className="mb-3 font-medium">
|
|
|
|
|
<MessageResponse>{answer.questionText}</MessageResponse>
|
|
|
|
|
</div>
|
2026-08-22 02:18:27 +03:00
|
|
|
|
|
|
|
|
{answer.options && answer.options.length > 0 && (
|
|
|
|
|
<div className="flex flex-col gap-1.5 text-sm">
|
|
|
|
|
{answer.options.map((opt) => {
|
|
|
|
|
const sel = selectedIdx.has(opt.index);
|
|
|
|
|
const key = isQuiz && correctIdx.has(opt.index);
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={opt.index}
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex items-start gap-2 rounded-lg border px-3 py-1.5",
|
|
|
|
|
sel && key && "border-green-500/60 bg-green-500/10",
|
|
|
|
|
sel && !key && isQuiz && "border-red-500/60 bg-red-500/10",
|
|
|
|
|
sel && !isQuiz && "border-primary bg-accent",
|
|
|
|
|
!sel && key && "border-green-500/40",
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{isQuiz && (
|
|
|
|
|
<span className="w-4 shrink-0">
|
|
|
|
|
{sel && key && "✓"}
|
|
|
|
|
{sel && !key && "✗"}
|
|
|
|
|
{!sel && key && "✓"}
|
|
|
|
|
</span>
|
|
|
|
|
)}
|
2026-08-22 03:23:11 +03:00
|
|
|
<span className={cn(!sel && "text-muted-foreground")}>
|
|
|
|
|
<MessageResponse>{opt.label}</MessageResponse>
|
|
|
|
|
</span>
|
2026-08-22 02:18:27 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{answer.other && <div className="mt-2 text-sm">“{answer.other}”</div>}
|
|
|
|
|
{answer.text && <div className="mt-2 whitespace-pre-wrap text-sm">“{answer.text}”</div>}
|
|
|
|
|
{answer.dontKnow && isQuiz && <div className="mt-2 text-sm text-muted-foreground">Answered “I don't know”.</div>}
|
|
|
|
|
|
|
|
|
|
{isQuiz && answer.explanation && (
|
|
|
|
|
<div className="mt-3 rounded-lg bg-muted px-3 py-2 text-sm text-muted-foreground">
|
|
|
|
|
<span className="font-medium text-foreground">Why: </span>
|
2026-08-22 03:23:11 +03:00
|
|
|
<MessageResponse className="inline">{answer.explanation}</MessageResponse>
|
2026-08-22 02:18:27 +03:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
{answer.note && <div className="mt-2 text-xs text-muted-foreground">Note: {answer.note}</div>}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|