import { useEffect, useRef, useState } from 'react'; import { CheckCircle2 } from 'lucide-react'; import { Component as PencilLoader } from '@/components/ui/loader-1'; import { resolveCanonicalCourseTitle } from '../../utils/courseTitleResolver'; interface GenerationLoaderProps { courseName: string; /** 'course' = building the learning path, 'assessment' = building exam questions */ mode?: 'course' | 'assessment'; } type Stage = { label: string; atSeconds: number }; const COURSE_STAGES: Omit[] = [ { label: 'Analyzing curriculum structure' }, { label: 'Curating verified learning resources' }, { label: 'Matching video content to topics' }, { label: 'Assembling your learning path' }, ]; const ASSESSMENT_STAGES: Omit[] = [ { label: 'Loading course context and video transcript signals' }, { label: 'Drafting question set across difficulty tiers' }, { label: 'Calibrating answer keys and grading rubrics' }, { label: 'Running final quality validation' }, ]; /** * Asymptotic progress: moves fast early, creeps toward ~92% but never * completes on its own — completion is only ever shown by the real result * replacing this screen. */ function progressPercent(elapsedMs: number): number { const t = elapsedMs / 1000; const pct = 92 * (1 - Math.exp(-t / 12)); return Math.min(92, Math.max(2, Math.round(pct))); } export function GenerationLoader({ courseName, mode = 'course' }: GenerationLoaderProps) { const baseStages = mode === 'assessment' ? ASSESSMENT_STAGES : COURSE_STAGES; // Spread stage handoffs across a realistic window (~8s apart) regardless of // actual model latency — stages reflect real pipeline phases, timed evenly. const stages: Stage[] = baseStages.map((stage, index) => ({ ...stage, atSeconds: 1 + index * 7, })); const [elapsedMs, setElapsedMs] = useState(0); const startRef = useRef(Date.now()); useEffect(() => { startRef.current = Date.now(); const interval = setInterval(() => { setElapsedMs(Date.now() - startRef.current); }, 200); return () => clearInterval(interval); }, []); const elapsedSeconds = Math.floor(elapsedMs / 1000); const activeStageIndex = stages.reduce( (acc, stage, index) => (elapsedSeconds >= stage.atSeconds ? index : acc), 0, ); const percent = progressPercent(elapsedMs); const title = mode === 'assessment' ? 'Preparing your assessment' : 'Creating your learning path'; const etaLabel = mode === 'assessment' ? 'Questions are generated fresh for this course — usually 15–30 seconds' : 'Your learning path is created fresh — usually 15–30 seconds'; return (
{/* Animated Pencil Loader */}

{title}

{resolveCanonicalCourseTitle(courseName)}

{/* Real progress bar — asymptotic toward 92% */}
{percent}% processed Elapsed: {elapsedSeconds}s
{/* Live pipeline checklist */}
{stages.map((stage, index) => { const isDone = index < activeStageIndex; const isActive = index === activeStageIndex; return (
{isDone ? ( ) : isActive ? ( ) : ( )} {stage.label}
); })}

{etaLabel}

); }