"use client"; import { Check, X } from "lucide-react"; import { useTranslation } from "react-i18next"; import type { ObjectiveReport } from "@/lib/learning-api"; import { formatAbsolute, formatRelative, type Translate } from "./format"; /** * The evidence behind one objective. * * The map answers "am I through the gate"; this answers "why" — which * questions were asked, what the learner said, what the engine did with it, * and when it comes back for review. The gate itself is shown as a bar with * the threshold marked, because a hard gate is only legible if you can see how * far away it is. */ export function ObjectiveDetail({ report, zh, }: { report: ObjectiveReport; zh: boolean; }) { const { t } = useTranslation(); const qualitative = report.gate === "qualitative"; const evidence = report.evidence ?? []; const evidenceCount = report.evidence_count ?? evidence.length; return (
{report.review && ( {report.review.due_at ? t("Due {{relative}} · {{absolute}}", { relative: formatRelative(report.review.due_at, zh), absolute: formatAbsolute(report.review.due_at, zh), }) : t("Not scheduled")} {t("memory {{retrievability}}% · stability {{stability}} days", { retrievability: Math.round(report.review.retrievability * 100), stability: report.review.stability.toFixed(1), })} {t("risk {{risk}}% · {{lapses}} lapses", { risk: Math.round(report.review.forgetting_risk * 100), lapses: report.review.lapse_count, })} {report.review.reason && ( {report.review.reason} )} )} {qualitative && report.explanation && ( {report.explanation} )} {report.attempts.length > 0 && (
{t("Attempts ({{correct}}/{{total}} correct)", { correct: report.correct_count, total: report.attempts.length, })}
    {[...report.attempts].reverse().map((attempt, index) => (
  • {attempt.is_correct ? ( ) : ( )}
    {attempt.prompt || t("(prompt unavailable)")}
    {t("You said: ")} {attempt.answer || t("(blank)")} {formatRelative(attempt.at, zh)}
  • ))}
)} {report.errors.length > 0 && ( {report.errors.map((record) => ( {t(record.error_type)} {record.retries > 0 && t(" · {{count}} retries", { count: record.retries })} {record.status === "graduated" && t(" · cleared")} ))} )} {report.explained && {report.explained.summary}} {!!report.required_visual_tasks?.length && {report.demonstrated_visual_tasks?.length ?? 0} / {report.required_visual_tasks.length}} {!!report.required_visual_tasks?.some((task) => !report.demonstrated_visual_tasks?.includes(task)) &&

{t("Independent visual evidence is still required for this objective.")}

} {report.attempts.some((attempt) => attempt.independent === false) &&

{t("Assisted practice is recorded separately from independent mastery.")}

} {evidence.length > 0 && (
{t("Retention evidence ({{count}})", { count: evidenceCount, })}
    {evidence.map((evidence, index) => (
  • {t(evidence.result)} · {t(evidence.assessment_type)} {evidence.visual_context?.task && ` · ${t("Visual practice")}${evidence.hints_used ? ` · ${t("Assisted")}` : ""}`} {evidence.quality !== null && ` · ${Math.round(evidence.quality * 100)}%`} {formatRelative(evidence.timestamp, zh)}
  • ))}
{evidenceCount > evidence.length && (

{t("Showing the latest 20 events")}

)}
)} {report.attempts.length === 0 && !report.explanation && (

{t( "No attempts yet. Once you work through this waypoint, its questions, your answers, and the grading evidence will appear here.", )}

)}
); } /** Mastery against the gate it has to clear. */ function GateBar({ report }: { report: ObjectiveReport }) { const { t } = useTranslation(); const qualitative = report.gate === "qualitative"; // A qualitative gate is a boolean, so all-or-nothing is the only honest // fill. `mastery` carries quiz accuracy for these objectives too, and // drawing that as gate progress is how a waypoint comes to show a full bar // beside a hollow dot — the learner reads "100%, still not cleared". const pct = qualitative ? report.mastered ? 100 : 0 : Math.round(report.mastery * 100); const thresholdPct = Math.round(report.threshold * 100); const perfectButBelowGate = report.gate === "quantitative" && report.attempts.length > 0 && report.correct_count === report.attempts.length && report.mastery < report.threshold; return (
{report.gate === "qualitative" ? t("Qualitative gate: explain it in your own words") : t("Quantitative gate: {{pct}}%", { pct: thresholdPct })} {pct}%
{report.gate === "quantitative" && (
)}
{perfectButBelowGate && (

{t( "Even with {{correct}}/{{total}} correct so far, mastery also weighs evidence volume, difficulty, and recent consistency. One more discriminating practice can raise it further.", { correct: report.correct_count, total: report.attempts.length }, )}

)} {qualitative && !report.mastered && report.attempts.length > 0 && (

{t( "Practice questions do not open this gate — it opens when you explain the idea in your own words and your tutor records that. Your answers here still count as practice.", )}

)}
); } function Row({ label, children, }: { label: string; children: React.ReactNode; }) { return (
{label}
{children}
); }