"use client"; import { useCallback, useEffect, useState } from "react"; import { useRouter } from "next/navigation"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Progress } from "@/components/ui/progress"; import { Separator } from "@/components/ui/separator"; import { ONBOARDING_STEPS } from "@/lib/onboarding-content"; import { ChevronLeft, ChevronRight, GraduationCap } from "lucide-react"; export default function OnboardingPage() { const router = useRouter(); const [currentStep, setCurrentStep] = useState(0); const [maxVisited, setMaxVisited] = useState(0); const [completing, setCompleting] = useState(false); const step = ONBOARDING_STEPS[currentStep]; const isLastStep = currentStep === ONBOARDING_STEPS.length - 1; const progress = ((currentStep + 1) / ONBOARDING_STEPS.length) * 100; // Check if already onboarded useEffect(() => { fetch("/api/onboarding") .then((res) => res.json()) .then((data) => { if (data.onboarded) router.push("/dashboard"); }); }, [router]); const goNext = useCallback(() => { if (isLastStep) return; const next = currentStep + 1; setCurrentStep(next); setMaxVisited((prev) => Math.max(prev, next)); window.scrollTo(0, 0); }, [currentStep, isLastStep]); const goBack = useCallback(() => { if (currentStep === 0) return; setCurrentStep(currentStep - 1); window.scrollTo(0, 0); }, [currentStep]); const completeOnboarding = useCallback(async () => { setCompleting(true); try { const res = await fetch("/api/onboarding", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ action: "complete" }), }); if (res.ok) { router.push("/dashboard"); } } finally { setCompleting(false); } }, [router]); // Keyboard navigation useEffect(() => { function handleKeyDown(e: KeyboardEvent) { if (e.key === "ArrowRight" && !isLastStep) { e.preventDefault(); goNext(); } else if (e.key === "ArrowLeft" && currentStep > 0) { e.preventDefault(); goBack(); } } window.addEventListener("keydown", handleKeyDown); return () => window.removeEventListener("keydown", handleKeyDown); }, [currentStep, isLastStep, goNext, goBack]); return (
{/* Progress header */}
Step {currentStep + 1} of {ONBOARDING_STEPS.length} Full Codebook
{/* Step nav dots */}
{ONBOARDING_STEPS.map((s, i) => (
{/* Main content */}
{currentStep + 1}
{step.title} {step.subtitle}
{/* Main text content */}
{step.content.map((paragraph, i) => (

{paragraph}

))}
{/* Examples */} {step.examples && step.examples.length > 0 && ( <>

Examples

{step.examples.map((example, i) => (

“{example.text}”

{example.category && ( {example.category} )} {example.specificity && ( {example.specificity} )}

{example.explanation}

))}
)} {/* Key points */} {step.keyPoints && step.keyPoints.length > 0 && ( <>

Key Points

    {step.keyPoints.map((point, i) => (
  • {point}
  • ))}
)} {/* Tip */} {step.tip && (

Tip: {step.tip}

)}
{isLastStep ? ( ) : ( )}
); }