import { useState, useRef, useLayoutEffect, memo } from 'react'; // Move constants outside component to avoid re-creation and make them accessible to memoized components const scopeOptions = [ { key: 'entire_paper', title: 'Entire Paper', desc: 'I want to understand the whole paper' }, { key: 'specific_section', title: 'Specific Section', desc: 'Focus on a particular section, chapter, equation, or formula' } ]; const depthOptions = [ { key: 'gist', title: 'Get the gist', desc: 'High-level understanding and main takeaways' }, { key: 'working_understanding', title: 'Working understanding', desc: 'Detailed comprehension I can discuss and apply' }, { key: 'reproduce', title: 'Reproduce results', desc: 'Deep enough to implement or reproduce the work' } ]; const styleOptions = [ { key: 'concepts', title: 'Concepts', desc: 'Focus on ideas, theories, and conceptual understanding' }, { key: 'mathematics', title: 'Mathematics', desc: 'Emphasize equations, proofs, and mathematical reasoning' }, { key: 'methods', title: 'Methods', desc: 'Concentrate on procedures, techniques, and implementation' }, { key: 'figures', title: 'Figures', desc: 'Focus on charts, diagrams, graphs, and visual elements' } ]; const chunkSizeOptions = [ { key: 'small', title: 'Small chunks', desc: 'Short, focused sections with frequent checkpoints' }, { key: 'medium', title: 'Medium chunks', desc: 'Balanced pace and depth' }, { key: 'large', title: 'Large chunks', desc: 'Longer sections, faster pace' } ]; const chunkingOptions = [ { key: 'guided', title: 'Generate learning chunks for me', badge: 'AI-Powered', desc: 'We\'ll automatically break down the paper into optimal learning sections' }, { key: 'manual', title: 'I\'ll highlight sections myself', desc: 'Use highlighting tools to select what you want to focus on' } ]; const familiarityLabels = ['New to it', 'Somewhat new', 'Comfortable', 'Very familiar', 'I\'ve taught this']; const OnboardingWizard = ({ fileName, academicBackground, onComplete }) => { const [currentStep, setCurrentStep] = useState('scope'); const [scope, setScope] = useState(null); const [scopeDetails, setScopeDetails] = useState(''); const [depth, setDepth] = useState(null); const [style, setStyle] = useState(null); const [familiarity, setFamiliarity] = useState(2); const [chunkSize, setChunkSize] = useState('medium'); const [useChunking, setUseChunking] = useState(null); const [familiarityText, setFamiliarityText] = useState(''); const [isLoading, setIsLoading] = useState(false); const [loadingPhase, setLoadingPhase] = useState(0); const stepNumbers = { scope: 1, depth: 2, style: 3, chunking: 4, familiarity: 5 }; const totalSteps = 5; const stepNumber = stepNumbers[currentStep]; const progressPct = (stepNumber / totalSteps) * 100; function onNext() { // Force sync of local state before navigating if (currentStep === 'scope' && scope === 'specific_section') { // Make sure the textarea is synced before navigation const textarea = document.getElementById('scope-details'); if (textarea) { setScopeDetails(textarea.value); } } if (currentStep === 'scope') setCurrentStep('depth'); else if (currentStep === 'depth') setCurrentStep('style'); else if (currentStep === 'style') setCurrentStep('chunking'); else if (currentStep === 'chunking') setCurrentStep('familiarity'); } function onBack() { if (currentStep === 'depth') setCurrentStep('scope'); else if (currentStep === 'style') setCurrentStep('depth'); else if (currentStep === 'chunking') setCurrentStep('style'); else if (currentStep === 'familiarity') setCurrentStep('chunking'); } function handleStart() { setIsLoading(true); setLoadingPhase(0); // Simulate loading phases const phases = [1200, 1200, 1400]; let i = 0; const timer = setInterval(() => { setLoadingPhase(prev => prev + 1); i += 1; if (i >= phases.length) { clearInterval(timer); // Call onComplete with all the collected data setTimeout(() => { onComplete({ scope, scopeDetails, depth, style, familiarity, chunkSize, useChunking, familiarityText, academicBackground }); }, 1000); } }, phases[0]); } if (isLoading) { return ; } return (
Step {stepNumber} of {totalSteps}
Setup
{currentStep === 'scope' && } {currentStep === 'depth' && } {currentStep === 'style' && } {currentStep === 'chunking' && } {currentStep === 'familiarity' && ( )}
{currentStep !== 'familiarity' && ( )} {currentStep === 'familiarity' && ( )}
); function StepDepth({ depth, setDepth }) { return (

How deep do you want to go?

Select the level of understanding you're aiming for.

{depthOptions.map(option => ( setDepth(option.key)} title={option.title} desc={option.desc} /> ))}
); } function StepStyle({ style, setStyle }) { return (

What's your learning style preference?

Choose the approach that works best for you.

{styleOptions.map(option => ( setStyle(option.key)} title={option.title} desc={option.desc} /> ))}
); } function StepChunking({ useChunking, setUseChunking, chunkSize, setChunkSize }) { return (

How would you like to structure your learning?

Choose how you want to break down the content.

{chunkingOptions.map(option => ( setUseChunking(option.key)} title={option.title} desc={option.desc} badge={option.badge} /> ))}
{useChunking === 'guided' && (

Preferred chunk size

{chunkSizeOptions.map(option => ( setChunkSize(option.key)} title={option.title} desc={option.desc} /> ))}
)}
); } function StepFamiliarity({ familiarity, setFamiliarity, familiarityText, setFamiliarityText, academicBackground }) { return (

How familiar are you with this topic?

This helps us adjust our teaching approach.

{academicBackground && (

Your background: {academicBackground}

)}
setFamiliarity(parseInt(e.target.value))} className="w-full accent-indigo-500" />
{familiarityLabels.map((label, i) => (
{label}
))}