"use client"; import { useMemo } from "react"; import type { CoursePlanResult } from "./learnAnythingTypes"; interface CoursePlanCardProps { coursePlan: CoursePlanResult; } /** * Display the backend-generated course plan. * Must show all available fields from CoursePlanResult. * Must respect truth rules: no fake claims, honest source labels. */ export function CoursePlanCard({ coursePlan }: CoursePlanCardProps) { const hasUploadedSource = coursePlan.data_source_label === "Uploaded source"; const contextItems = [ ["Class", coursePlan.student_context.class_level], ["Syllabus", coursePlan.student_context.syllabus], ["Subject", coursePlan.student_context.subject], ["Chapter", coursePlan.student_context.chapter], ["Exam", coursePlan.student_context.exam_date], ["Daily time", coursePlan.student_context.daily_study_time], ["Goal", coursePlan.student_context.goal], ].filter(([, value]) => value); // Format duration const formatDuration = (minutes: number) => { if (minutes < 60) return `${minutes} min`; const hours = Math.floor(minutes / 60); const remainingMinutes = minutes % 60; if (remainingMinutes === 0) return hours === 1 ? "1 hour" : `${hours} hours`; return hours === 1 ? `1 hour ${remainingMinutes} min` : `${hours} hours ${remainingMinutes} min`; }; // Format course type label const courseTypeLabel = useMemo(() => { if (coursePlan.source_basis === "source_upload") return "Source-backed course"; if (coursePlan.source_basis === "catalog_seed") return "Catalog-based course"; if (coursePlan.source_basis === "syllabus") return "Syllabus-based course"; return "Starter course plan"; }, [coursePlan.source_basis]); return (
{/* Header */}

{coursePlan.title}

{/* Source Badge */} {coursePlan.data_source_label}
Level: {coursePlan.learner_level || "General"} Subject: {coursePlan.subject_area || "General"} Total: {coursePlan.lessons_total} lessons / {formatDuration(coursePlan.estimated_total_minutes)} {coursePlan.estimated_study_time && ( Study time: {coursePlan.estimated_study_time} )}
{/* Trust Notes - always visible if present */} {coursePlan.trust_notes && coursePlan.trust_notes.length > 0 && (
{coursePlan.trust_notes.map((note, index) => ( {note} ))}
)}
{/* Main Content */}
{/* Confidence */} {coursePlan.confidence > 0 && (
Confidence:
{(coursePlan.confidence * 100).toFixed(0)}%
)} {contextItems.length > 0 && (

Student Context

{contextItems.map(([label, value]) => (

{label}

{value}

))}
)} {coursePlan.lesson_outline.length > 0 && (

Lesson Outline

{coursePlan.lesson_outline.map((item, index) => (
{index + 1}

{item}

))}
)} {coursePlan.prerequisite_check.length > 0 && (

Prerequisite Check

    {coursePlan.prerequisite_check.map((item, index) => (
  • {item}
  • ))}
)} {coursePlan.concept_explanation && (

Concept Explanation

{coursePlan.concept_explanation.title}

{coursePlan.concept_explanation.explanation}

{coursePlan.concept_explanation.board_exam_focus && (

{coursePlan.concept_explanation.board_exam_focus}

)}
)} {coursePlan.derivation_or_problem_steps.length > 0 && (

Derivation / Problem Steps

{coursePlan.derivation_or_problem_steps.map((item) => (

{item.title}

    {item.steps.map((step, index) => (
  1. {index + 1}. {step}
  2. ))}
{item.common_mistake && (

Common mark loss: {item.common_mistake}

)}
))}
)} {/* Prerequisites */} {coursePlan.prerequisites && coursePlan.prerequisites.length > 0 && (

Prerequisites

{coursePlan.prerequisites.map((prereq, index) => ( {prereq} ))}
)} {/* Final Outcome */} {coursePlan.final_outcome && (

Final Outcome

{coursePlan.final_outcome}

)} {/* Next Action */} {coursePlan.next_action && (

Next Action

{coursePlan.next_action}

)} {/* Key Concepts */} {coursePlan.key_concepts && coursePlan.key_concepts.length > 0 && (

Key Concepts

{coursePlan.key_concepts.map((concept, index) => ( {concept} ))}
)} {coursePlan.practice_questions.length > 0 && ( )} {coursePlan.pyq_style_questions.length > 0 && ( )} {coursePlan.weak_topic_repairs.length > 0 && (

Weak Topic Repair

{coursePlan.weak_topic_repairs.map((repair) => (

{repair.topic}

{repair.symptom}

{repair.repair_task}

))}
)} {coursePlan.revision_plan.length > 0 && (

Revision Plan

{coursePlan.revision_plan.map((item) => (

{item.timing}

{item.estimated_minutes} min

{item.task}

{item.purpose}

))}
)} {/* Modules - Main Content */} {coursePlan.modules && coursePlan.modules.length > 0 && (

Course Modules

{coursePlan.modules.map((module, moduleIndex) => (
{moduleIndex + 1}

{module.title}

{module.estimated_minutes > 0 && (

~{formatDuration(module.estimated_minutes)}

)}

Source: {module.source_basis}

{/* Module Lessons */}
{module.lessons.map((lesson, lessonIndex) => (

{lesson.title}

{lesson.task}

{lesson.duration_minutes} min
))}
))}
)} {/* Practice Tasks */} {coursePlan.practice_tasks && coursePlan.practice_tasks.length > 0 && (

Practice Tasks

{coursePlan.practice_tasks.map((task, index) => (

{task.title}

{task.description || task.task_type}

Type: {task.task_type}

))}
)} {/* Quizzes */} {coursePlan.quizzes && coursePlan.quizzes.length > 0 && (

Quizzes

{coursePlan.quizzes.map((quiz, index) => (

{quiz.title}

{quiz.question_count} questions

{quiz.focus_areas && quiz.focus_areas.length > 0 && (

Focus: {quiz.focus_areas.join(", ")}

)}
))}
)} {/* Revision Checkpoints */} {coursePlan.revision_checkpoints && coursePlan.revision_checkpoints.length > 0 && (

Revision Checkpoints

{coursePlan.revision_checkpoints.map((checkpoint, index) => (

{checkpoint.title}

{checkpoint.estimated_minutes} minutes

{checkpoint.focus_areas && checkpoint.focus_areas.length > 0 && (

Focus: {checkpoint.focus_areas.join(", ")}

)}
))}
)}
{/* Footer */}

Generated by DocDoe AI | {courseTypeLabel} {!hasUploadedSource && " | No uploaded source used"}

); } function QuestionSection({ title, questions, }: { title: string; questions: CoursePlanResult["practice_questions"]; }) { return (

{title}

{questions.map((question) => (
{question.marks} marks {question.question_type.replaceAll("_", " ")}

{question.question}

{question.answer_hint && (

{question.answer_hint}

)}
))}
); }