"use client"; import { BookOpen, Calculator, ChevronDown, ChevronUp, Lightbulb, Target, Zap, } from "lucide-react"; import { useState } from "react"; import type { DeepChapterOutput, VisualLessonOutput } from "@/lib/api/types"; export function DeepChapterCard({ data, topic }: { data: DeepChapterOutput; topic: string }) { const [expandedSections, setExpandedSections] = useState>(new Set(["concepts"])); const toggle = (key: string) => { setExpandedSections((prev) => { const next = new Set(prev); if (next.has(key)) next.delete(key); else next.add(key); return next; }); }; const dataLabel = data.data_source_label; const pyqPatterns = data.pyq_patterns ?? []; const hasRealPyq = pyqPatterns.some((p) => p.question && p.source === "Seen in uploaded PYQs"); return (
{/* Header */}
Deep Chapter Teaching

{data.chapter_title || topic}

{/* Data source label */} {dataLabel && (
{dataLabel}
)} {/* Syllabus position */}

{data.syllabus_position}

{/* What this chapter is about */} {data.what_this_chapter_is_about && (

{data.what_this_chapter_is_about}

)} {/* Prerequisites */} {data.prerequisite_topics?.length > 0 && ( } expanded={expandedSections.has("prereqs")} onToggle={() => toggle("prereqs")} count={data.prerequisite_topics.length} >
    {data.prerequisite_topics.map((p, i) => (
  • {p}
  • ))}
)} {/* Deep concept sections */} {data.deep_concept_sections?.length > 0 && ( } expanded={expandedSections.has("concepts")} onToggle={() => toggle("concepts")} count={data.deep_concept_sections.length} >
{data.deep_concept_sections.map((concept, i) => (

{concept.name}

{concept.simple_explanation}

{concept.deep_explanation && (

{concept.deep_explanation}

)} {concept.equation && (

{concept.equation}

)} {concept.real_example && (

Example: {concept.real_example}

)} {concept.common_mistake && (

Mistake: {concept.common_mistake}

)} {concept.practice_question && (

Try: {concept.practice_question}

)}
))}
)} {/* Derivations */} {data.derivations?.length > 0 && ( } expanded={expandedSections.has("derivations")} onToggle={() => toggle("derivations")} count={data.derivations.length} >
{data.derivations.map((d, i) => (

{d.name}

{d.symbols?.length > 0 && (

Symbols: {d.symbols.join(", ")}

)} {d.steps?.length > 0 && (
    {d.steps.map((step, j) => (
  1. {j + 1}. {step}
  2. ))}
)} {d.final_formula && (

{d.final_formula}

)} {d.unit_check &&

{d.unit_check}

}
))}
)} {/* Formulas */} {data.formulas?.length > 0 && ( } expanded={expandedSections.has("formulas")} onToggle={() => toggle("formulas")} count={data.formulas.length} >
{data.formulas.map((f, i) => (
{f.name} {f.formula} [{f.unit}]
))}
)} {/* Common mistakes */} {data.common_mistakes?.length > 0 && ( toggle("mistakes")} count={data.common_mistakes.length} >
    {data.common_mistakes.map((m, i) => (
  • {m}
  • ))}
)} {/* Important questions */} {data.important_questions?.length > 0 && ( toggle("important")} count={data.important_questions.length} >
    {data.important_questions.map((q, i) => (
  • {q}
  • ))}
)} {/* PYQ */} {hasRealPyq ? ( toggle("pyq")} count={pyqPatterns.filter((p) => p.question).length} >
{pyqPatterns.filter((p) => p.question).map((p, i) => (

{p.question}

{p.marks} marks — {p.year} {p.source === "Seen in uploaded PYQs" && ( Uploaded PYQ )}
))}
) : (

Upload previous year papers to unlock pattern analysis across them.

Upload previous year question papers to see repeated topics, marks distribution, and evidence-backed insights.

)} {/* Quick revision */} {data.quick_revision_box?.length > 0 && (

Quick Revision

    {data.quick_revision_box.map((r, i) => (
  • {r}
  • ))}
)} {/* Practice */} {data.practice_questions?.length > 0 && (

Practice

    {data.practice_questions.map((q, i) => (
  • {q}
  • ))}
)} {/* Next action */} {data.next_best_action && (

{data.next_best_action}

)} {/* Source */} {data.source_used && (

Source: {data.source_used}

)}
); } export function VisualLessonCard({ data, topic }: { data: VisualLessonOutput; topic: string }) { const [expandedFrames, setExpandedFrames] = useState>(new Set(["derivation"])); const toggle = (key: string) => { setExpandedFrames((prev) => { const next = new Set(prev); if (next.has(key)) next.delete(key); else next.add(key); return next; }); }; const dataLabel = data.data_source_label; return (
Visual Lesson Plan

{data.lesson_title || topic}

{/* Data source label */} {dataLabel && (
{dataLabel}
)}

{data.syllabus_position}

{data.learning_goal}

{/* Stats */}
{data.total_frames} frames {Math.round(data.total_estimated_seconds / 60)} min {data.visual_style}
{/* Concept flow */} {data.concept_flow?.length > 0 && (

Concept Flow

{data.concept_flow.map((step, i) => ( {i + 1}. {step} ))}
)} {/* Derivation frames */} {data.derivation_frames?.length > 0 && ( } expanded={expandedFrames.has("derivation")} onToggle={() => toggle("derivation")} count={data.derivation_frames.length} >
{data.derivation_frames.map((frame) => ( ))}
)} {/* Diagram frames */} {data.diagram_frames?.length > 0 && ( toggle("diagram")} count={data.diagram_frames.length} >
{data.diagram_frames.map((frame) => ( ))}
)} {/* Numerical frames */} {data.numerical_frames?.length > 0 && ( } expanded={expandedFrames.has("numerical")} onToggle={() => toggle("numerical")} count={data.numerical_frames.length} >
{data.numerical_frames.map((frame) => ( ))}
)} {/* Narration script */} {data.narration_script && (

Narration Script

{data.narration_script.substring(0, 500)}{data.narration_script.length > 500 ? "..." : ""}

)}
); } function FrameCard({ frame }: { frame: { frame_number: number; teaching_purpose: string; visual_type: string; on_screen_text: string; narration: string; why_this_helps: string; exam_connection: string; duration_seconds: number; common_misunderstanding_fixed?: string } }) { return (
Frame {frame.frame_number} {frame.visual_type} {frame.duration_seconds}s

{frame.teaching_purpose}

{frame.on_screen_text}

{frame.narration}

{frame.common_misunderstanding_fixed && (

Fixes: {frame.common_misunderstanding_fixed}

)}

Exam: {frame.exam_connection}

); } function CollapsibleSection({ title, icon, expanded, onToggle, count, children, }: { title: string; icon?: React.ReactNode; expanded: boolean; onToggle: () => void; count: number; children: React.ReactNode; }) { return (
{expanded &&
{children}
}
); }