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
Select the level of understanding you're aiming for.
Choose the approach that works best for you.
Choose how you want to break down the content.
This helps us adjust our teaching approach.
{academicBackground && (Your background: {academicBackground}
{fileName}
Setting up your personalized learning experience...
Choose what you want to focus on in this paper.