"use client"; import React, { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { motion, AnimatePresence } from 'framer-motion'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { Progress } from '@/components/ui/progress'; import { CheckCircle, ArrowRight, ArrowLeft, Bot, Sparkles, Zap, Brain } from 'lucide-react'; import { Logo } from '@/components/Logo'; import { useLLMConfigs, useLLMPreferences } from '@/hooks/use-llm-configs'; import { AddProviderStep } from '@/components/onboard/add-provider-step'; import { AssignRolesStep } from '@/components/onboard/assign-roles-step'; import { CompletionStep } from '@/components/onboard/completion-step'; const TOTAL_STEPS = 3; const OnboardPage = () => { const router = useRouter(); const { llmConfigs, loading: configsLoading, refreshConfigs } = useLLMConfigs(); const { preferences, loading: preferencesLoading, isOnboardingComplete, refreshPreferences } = useLLMPreferences(); const [currentStep, setCurrentStep] = useState(1); const [hasUserProgressed, setHasUserProgressed] = useState(false); // Check if user is authenticated useEffect(() => { const token = localStorage.getItem('surfsense_bearer_token'); if (!token) { router.push('/login'); return; } }, [router]); // Track if user has progressed beyond step 1 useEffect(() => { if (currentStep > 1) { setHasUserProgressed(true); } }, [currentStep]); // Redirect to dashboard if onboarding is already complete and user hasn't progressed (fresh page load) useEffect(() => { if (!preferencesLoading && isOnboardingComplete() && !hasUserProgressed) { router.push('/dashboard'); } }, [preferencesLoading, isOnboardingComplete, hasUserProgressed, router]); const progress = (currentStep / TOTAL_STEPS) * 100; const stepTitles = [ "Add LLM Provider", "Assign LLM Roles", "Setup Complete" ]; const stepDescriptions = [ "Configure your first model provider", "Assign specific roles to your LLM configurations", "You're all set to start using SurfSense!" ]; const canProceedToStep2 = !configsLoading && llmConfigs.length > 0; const canProceedToStep3 = !preferencesLoading && preferences.long_context_llm_id && preferences.fast_llm_id && preferences.strategic_llm_id; const handleNext = () => { if (currentStep < TOTAL_STEPS) { setCurrentStep(currentStep + 1); } }; const handlePrevious = () => { if (currentStep > 1) { setCurrentStep(currentStep - 1); } }; const handleComplete = () => { router.push('/dashboard'); }; if (configsLoading || preferencesLoading) { return (

Loading your configuration...

); } return (
{/* Header */}

Welcome to SurfSense

Let's configure your SurfSense to get started

{/* Progress */}
Step {currentStep} of {TOTAL_STEPS}
{Math.round(progress)}% Complete
{Array.from({ length: TOTAL_STEPS }, (_, i) => { const stepNum = i + 1; const isCompleted = stepNum < currentStep; const isCurrent = stepNum === currentStep; return (
{isCompleted ? : stepNum}

{stepTitles[i]}

); })}
{/* Step Content */} {currentStep === 1 && } {currentStep === 2 && } {currentStep === 3 && } {stepTitles[currentStep - 1]} {stepDescriptions[currentStep - 1]} {currentStep === 1 && } {currentStep === 2 && } {currentStep === 3 && } {/* Navigation */}
{currentStep < TOTAL_STEPS && ( )} {currentStep === TOTAL_STEPS && ( )}
); }; export default OnboardPage;