"use client" import { useState, useEffect } from 'react' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { X, ChevronRight, ChevronLeft, Sparkles } from 'lucide-react' import { UserCategory, ExperienceLevel } from '@/types/recommendations' import { useLocale } from '@/contexts/LocaleContext' import { RECOMMENDATION_PRESETS } from '@/data/recommendationPresets' import { CATEGORY_ICONS } from '@/constants/categoryIcons' interface OnboardingModalProps { isOpen: boolean onClose: () => void onComplete: (data: { categories: UserCategory[] selectedOS?: string experienceLevel: ExperienceLevel }) => void detectedOS: string } const PLATFORMS = [ { id: 'windows', name: 'Windows' }, { id: 'macos', name: 'macOS' }, { id: 'ubuntu', name: 'Ubuntu' }, { id: 'debian', name: 'Debian' }, { id: 'arch', name: 'Arch Linux' }, { id: 'fedora', name: 'Fedora' } ] const iconSlug: Record = { debian: 'debian', ubuntu: 'ubuntu', fedora: 'fedora', arch: 'archlinux', windows: 'windows', macos: 'apple' } const iconBase = (slug: string) => `https://cdn.jsdelivr.net/npm/simple-icons@latest/icons/${slug}.svg` export function OnboardingModal({ isOpen, onClose, onComplete, detectedOS }: OnboardingModalProps) { const { t } = useLocale() const [step, setStep] = useState(1) const [selectedCategories, setSelectedCategories] = useState([]) // Default to ubuntu if OS detection fails const [selectedOS, setSelectedOS] = useState( detectedOS !== 'unknown' ? detectedOS : 'ubuntu' ) const [experienceLevel, setExperienceLevel] = useState('beginner') // Reset state when modal opens useEffect(() => { if (isOpen) { setStep(1) // Keep current OS selection or use detected setSelectedOS(detectedOS !== 'unknown' ? detectedOS : 'ubuntu') } }, [isOpen, detectedOS]) if (!isOpen) return null const handleCategoryToggle = (category: UserCategory) => { setSelectedCategories(prev => { if (prev.includes(category)) { return prev.filter(c => c !== category) } // Limit to 3 categories if (prev.length >= 3) { return [...prev.slice(1), category] } return [...prev, category] }) } const handleNext = () => { if (step < 3) { setStep(step + 1) } } const handleBack = () => { if (step > 1) { setStep(step - 1) } } const handleComplete = () => { if (selectedCategories.length === 0) { return } onComplete({ categories: selectedCategories, selectedOS: selectedOS, experienceLevel }) // Close modal onClose() } const canProceed = () => { if (step === 1) return selectedCategories.length > 0 if (step === 2) return selectedOS !== 'unknown' if (step === 3) return true return false } return (
{t('onboarding.title')}
{t('onboarding.subtitle')} {/* Progress indicator */}
{[1, 2, 3].map(i => (
))}
{/* Step 1: Categories */} {step === 1 && (

{t('onboarding.step1.title')}

{t('onboarding.step1.description')}

{RECOMMENDATION_PRESETS.map(preset => { const Icon = CATEGORY_ICONS[preset.category] return ( ) })}
{selectedCategories.length > 0 && (

{t('onboarding.step1.selected', { count: selectedCategories.length })}

)}
)} {/* Step 2: Operating System */} {step === 2 && (

{t('onboarding.step2.title')}

{t('onboarding.step2.description')}

{detectedOS !== 'unknown' && (

{t('onboarding.step2.detected', { os: detectedOS })}

)}
{PLATFORMS.map(platform => ( ))}
)} {/* Step 3: Experience Level */} {step === 3 && (

{t('onboarding.step3.title')}

{t('onboarding.step3.description')}

{(['beginner', 'intermediate', 'advanced'] as ExperienceLevel[]).map(level => ( ))}
)} {/* Navigation Buttons */}
{step > 1 && ( )} {step < 3 ? ( ) : ( )}
) }