"use client"; import { BookOpen, ClipboardList, Download, FileQuestion, Layers3, LoaderCircle, Moon, RefreshCw, ShieldCheck, Sparkles, Upload, Video, } from "lucide-react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { inferStudyIntentFromPrompt, type StudyIntent, } from "@/lib/study-intents"; import type { StudyCard } from "./types"; import { RichStudyCard } from "./StudyCardPrimitives"; import { StagedThinkingLine } from "./StagedThinking"; import { ExamAnswerCard, ExplanationCard, FlashcardDeckCard, NotesCard, QuizCard, RevisionPlanCard, StudyPathCard, VideoPlanCard, } from "./StudyResultCards"; import { AnswerCorrectionCard } from "./AnswerCorrectionCard"; import { DeepChapterCard, VisualLessonCard } from "./DeepChapterCards"; import { InlineVideoRender } from "./InlineVideoRender"; import { PyqAnalysisCard } from "./PyqAnalysisCard"; import { StructuredStudyResponseCard } from "./StructuredStudyResponseCard"; import { PlainAssistantMessage } from "./PlainAssistantMessage"; export { PlainAssistantMessage }; // ── Casual / welcome card ────────────────────────────────────────────────────── function WelcomeCard({ card, onAction }: { card: Extract; onAction: (intent: StudyIntent, prompt: string) => void }) { const suggestions: Array<{ label: string; intent: StudyIntent; prompt: string; icon: typeof BookOpen }> = [ { label: "Teach a topic", intent: "teach_topic", prompt: "Teach me ", icon: BookOpen }, { label: "One-night plan", intent: "create_revision_plan", prompt: "I need to learn ", icon: Moon }, { label: "Make notes", intent: "generate_notes", prompt: "Make notes on ", icon: ClipboardList }, { label: "Quiz me", intent: "generate_quiz", prompt: "Make a quiz on ", icon: FileQuestion }, { label: "Study video", intent: "create_video_plan", prompt: "Create a study video plan for ", icon: Video }, ]; return (
Study Chat

{children}

, strong: ({ children }) => {children}, }} > {card.message}
{suggestions.map((s) => { const Icon = s.icon; return ( ); })}
); } // ── Needs-source CTA card ────────────────────────────────────────────────────── function NeedsSourceCard({ card, onUpload, }: { card: Extract; onUpload?: () => void; }) { return (

{card.message}

{onUpload ? ( ) : null}
); } // ── Clarify options card ─────────────────────────────────────────────────────── const CLARIFY_OPTIONS: Array<{ label: string; intent: StudyIntent; prompt: string; icon: typeof BookOpen }> = [ { label: "Explain topic", intent: "teach_topic", prompt: "Explain ", icon: BookOpen }, { label: "One-night plan", intent: "create_revision_plan", prompt: "I need to learn ", icon: Moon }, { label: "Make notes", intent: "generate_notes", prompt: "Make notes on ", icon: ClipboardList }, { label: "Quiz me", intent: "generate_quiz", prompt: "Quiz me on ", icon: FileQuestion }, { label: "Flashcards", intent: "generate_flashcards", prompt: "Make flashcards for ", icon: Layers3 }, { label: "Study plan", intent: "continue_learning", prompt: "Build my study plan", icon: Moon }, ]; function ClarifyCard({ onAction, }: { card: Extract; onAction: (intent: StudyIntent, prompt: string) => void; }) { return (

Specify the topic, exam, time left, or goal. I can work from a typed question, pasted text, or an uploaded source.

{CLARIFY_OPTIONS.map((opt) => { const Icon = opt.icon; return ( ); })}
); } // ── Real PYQ papers card ─────────────────────────────────────────────────────── function PyqPapersCard({ card }: { card: Extract }) { const data = card.data; const papers = (data.papers ?? []).filter((p) => p?.url); const years = (data.years_covered ?? []).join(", "); return (

Real previous papers

{data.board} {data.level !== "SSLC" ? data.level : ""} — actual board papers

Verified Kerala board papers with answer keys — not AI-generated.{years ? ` Years: ${years}.` : ""}

{data.trust_note}

); } export function StudyCardRenderer({ card, onAction, onUpload, onStartRender, }: { card: StudyCard; onAction: (intent: StudyIntent, prompt: string) => void; onUpload?: () => void; onStartRender?: (topic: string, sourceId: string | null, minutes: number) => void; }) { if (card.kind === "streaming") { return (
{card.evidenceLabel ? (

Basis: {card.evidenceLabel}

) : null}
); } if (card.kind === "loading") { return (
); } if (card.kind === "error") { const variant = card.variant ?? "generic"; const copy: Record = { quota: { title: "You've hit today's limit", eyebrow: "Plan limit", hint: "Your limit refreshes later. Upgrade your plan for more.", }, daily_limit: { title: "Today's AI allowance is used", eyebrow: "Daily limit", hint: "Your saved classes and notes are still available.", }, rate_limit: { title: "Going a bit fast", eyebrow: "Slow down", hint: "Wait a few seconds, then send again.", }, auth: { title: "Session expired", eyebrow: "Sign in needed", hint: "Sign in again to pick up where you left off.", }, offline: { title: "Request did not complete", eyebrow: "Study tools busy", hint: "This usually clears in a moment. Try again.", }, generic: { title: "Request did not complete", eyebrow: "Something went wrong", hint: "Try again, or rephrase your request.", }, }; const { title, eyebrow, hint } = copy[variant] ?? copy.generic; return (

{card.message}

{hint ?

{hint}

: null} {variant === "auth" ? ( Sign in ) : variant === "daily_limit" ? ( Continue saved classes ) : variant === "quota" ? ( See plans ) : ( )}
); } // ── New response-mode card kinds ────────────────────────────────────────── if (card.kind === "welcome") return ; if (card.kind === "needs_source") return ; if (card.kind === "clarify") return ; if (card.kind === "pyq_papers") return ; if (card.kind === "notes") return ; if (card.kind === "quiz") return ; if (card.kind === "flashcards") return ; if (card.kind === "exam_answer") return ; if (card.kind === "revision_plan") return ; if (card.kind === "study_path") return ; if (card.kind === "video_plan") return ; if (card.kind === "video_render") return ; if (card.kind === "answer_correction") return ; if (card.kind === "deep_chapter") return ; if (card.kind === "structured_study_response") return ; if (card.kind === "visual_lesson") return ; if (card.kind === "pyq_analysis") return ; return ; }