"use client"; // ─── Chapter Intelligence Header ────────────────────────────────────────────── // Surfaces exam intelligence from curriculum metadata above lesson content. // Renders nothing if chapter cannot be matched (graceful degradation). import { Clock, Flame, Star, BookMarked, AlertTriangle } from "lucide-react"; import { searchChapters } from "@/lib/curriculum/index"; import { getExamProfile, pyqLabel, difficultyLabel, } from "@/lib/curriculum/exam-intelligence"; import { cn } from "@/lib/utils"; // ─── Helpers ────────────────────────────────────────────────────────────────── function normalizeLevel(raw: string | null | undefined): string | undefined { if (!raw) return undefined; const s = raw.toLowerCase(); if (s.includes("sslc") || s.includes("10")) return "SSLC"; if (s.includes("+2") || s.includes("12") || s.includes("plus two") || s.includes("class 12")) return "+2"; if (s.includes("+1") || s.includes("11") || s.includes("plus one") || s.includes("class 11")) return "+1"; return undefined; } // ─── Sub-components ─────────────────────────────────────────────────────────── function IntelChip({ children, variant = "neutral", }: { children: React.ReactNode; variant?: "neutral" | "green" | "amber" | "violet" | "red"; }) { const variants = { neutral: "border-white/[0.08] bg-white/[0.04] text-white/50", green: "border-emerald-400/20 bg-emerald-400/8 text-emerald-400", amber: "border-amber-400/20 bg-amber-400/8 text-amber-400", violet: "border-violet-400/20 bg-violet-400/8 text-violet-400", red: "border-red-400/20 bg-red-400/8 text-red-400", }; return ( {children} ); } // ─── Main component ─────────────────────────────────────────────────────────── type Props = { /** Chapter name or topic extracted from study request analysis */ chapterQuery: string; /** Level hint: "+1", "+2", "SSLC", grade string, or exam string */ levelHint?: string | null; }; export function ChapterIntelHeader({ chapterQuery, levelHint }: Props) { if (!chapterQuery) return null; const level = normalizeLevel(levelHint); const results = searchChapters(chapterQuery, { level, limit: 1 }); if (results.length === 0) return null; const { chapter, level: foundLevel, subjectSlug } = results[0]; const profile = getExamProfile(chapter); const priorityVariant: "green" | "amber" | "violet" | "red" = profile.priority === "critical" ? "red" : profile.priority === "important" ? "amber" : profile.priority === "moderate" ? "violet" : "neutral" as "violet"; const priorityLabel = profile.priority === "critical" ? "Exam critical" : profile.priority === "important" ? "High priority" : profile.priority === "moderate" ? "Worth studying" : "Low priority"; return (
{/* Top row: chapter identity */}
{chapter.name} · {foundLevel} {subjectSlug.charAt(0).toUpperCase() + subjectSlug.slice(1)}
{/* Badge row */}
{/* Priority */} {priorityLabel} {/* PYQ frequency */} {pyqLabel(chapter)} {/* Difficulty */} {difficultyLabel(chapter)} {/* Study time */} {chapter.estimatedMinutes} min {/* Formulas count */} {chapter.formulas && chapter.formulas.length > 0 ? ( {chapter.formulas.length} formula{chapter.formulas.length !== 1 ? "s" : ""} ) : null} {/* Last night priority */} {chapter.lastNightPriority >= 4 ? ( Study tonight ) : null}
{/* Insight line */}

{profile.action} {chapter.examWeightageMarks ? ` · ~${chapter.examWeightageMarks} marks in theory paper` : null}

{/* Prerequisites */} {chapter.prerequisites.length > 0 ? (
Before this, revise: {chapter.prerequisites.map((prereq) => ( {prereq} ))}
) : null} {/* Top formulas preview */} {chapter.formulas && chapter.formulas.length > 0 ? (
{chapter.formulas.slice(0, 3).map((f) => ( {f} ))} {chapter.formulas.length > 3 ? ( +{chapter.formulas.length - 3} more ) : null}
) : null}
); }