'use client'; import { useState, useCallback } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { clsx } from 'clsx'; import { UserCircle, Building2, CheckCircle2, PartyPopper, Import, MessageCircle, GitBranch, Users, ChevronLeft, ChevronRight, Briefcase, Sparkles, } from 'lucide-react'; import { useI18n } from '@/i18n'; /* ---------- Types ---------- */ type Phase = 'welcome' | 'firstValue' | 'checklist'; type Role = 'salesManager' | 'salesRep' | 'executive' | 'other'; type Industry = 'realEstate' | 'automotive' | 'healthcare' | 'services' | 'other'; interface OnboardingFlowProps { onComplete?: () => void; className?: string; } /* ---------- Animation ---------- */ const slideVariants = { enter: (dir: number) => ({ x: dir > 0 ? 80 : -80, opacity: 0 }), center: { x: 0, opacity: 1 }, exit: (dir: number) => ({ x: dir > 0 ? -80 : 80, opacity: 0 }), }; /* ---------- Phase 1: Welcome ---------- */ function WelcomePhase({ role, setRole, industry, setIndustry, onNext, }: { role: Role | null; setRole: (r: Role) => void; industry: Industry | null; setIndustry: (i: Industry) => void; onNext: () => void; }) { const { t, isArabic } = useI18n(); const [step, setStep] = useState<'role' | 'industry'>('role'); const roles: { key: Role; icon: typeof UserCircle }[] = [ { key: 'salesManager', icon: UserCircle }, { key: 'salesRep', icon: Briefcase }, { key: 'executive', icon: Building2 }, { key: 'other', icon: Users }, ]; const industries: { key: Industry; label: string }[] = [ { key: 'realEstate', label: t('onboarding.industryRealEstate') }, { key: 'automotive', label: t('onboarding.industryAutomotive') }, { key: 'healthcare', label: t('onboarding.industryHealthcare') }, { key: 'services', label: t('onboarding.industryServices') }, { key: 'other', label: t('onboarding.industryOther') }, ]; const roleLabels: Record = { salesManager: t('onboarding.roleSalesManager'), salesRep: t('onboarding.roleSalesRep'), executive: t('onboarding.roleExecutive'), other: t('onboarding.roleOther'), }; return (

{t('onboarding.welcomeTitle')}

{t('onboarding.welcomeSubtitle')}

{step === 'role' ? (

{t('onboarding.roleQuestion')}

{roles.map((r) => { const Icon = r.icon; const selected = role === r.key; return ( ); })}
) : (

{t('onboarding.industryQuestion')}

{industries.map((ind) => { const selected = industry === ind.key; return ( ); })}
)}
); } /* ---------- Phase 2: First Value ---------- */ function FirstValuePhase({ onNext }: { onNext: () => void }) { const { t, isArabic } = useI18n(); const [created, setCreated] = useState(false); const handleCreate = () => { setCreated(true); setTimeout(onNext, 1800); }; return (

{t('onboarding.firstValueTitle')}

{t('onboarding.firstValueSubtitle')}

{!created ? (
{t('onboarding.sampleDealName')}
{isArabic ? 'ر.س' : 'SAR'} {t('onboarding.sampleDealValue')}
{t('onboarding.sampleContactName')} — {t('onboarding.sampleCompany')}
{t('onboarding.createDeal')}
) : (

{t('onboarding.celebration')}

{t('onboarding.dealCreated')}

)}
); } /* ---------- Phase 3: Checklist ---------- */ interface ChecklistItem { key: string; label: string; icon: typeof Import; done: boolean; } function ChecklistPhase({ onComplete }: { onComplete?: () => void }) { const { t } = useI18n(); const [items, setItems] = useState([ { key: 'import', label: t('onboarding.checkImportContacts'), icon: Import, done: false }, { key: 'whatsapp', label: t('onboarding.checkConnectWhatsApp'), icon: MessageCircle, done: false }, { key: 'pipeline', label: t('onboarding.checkSetupPipeline'), icon: GitBranch, done: false }, { key: 'team', label: t('onboarding.checkInviteTeam'), icon: Users, done: false }, ]); const doneCount = items.filter((i) => i.done).length; const progress = Math.round((doneCount / items.length) * 100); const toggleItem = useCallback((key: string) => { setItems((prev) => prev.map((item) => item.key === key ? { ...item, done: !item.done } : item, ), ); }, []); return (

{t('onboarding.checklistTitle')}

{/* Progress */}
{progress}% {t('onboarding.checklistProgress')}
{/* Items */}
    {items.map((item) => { const Icon = item.icon; return ( toggleItem(item.key)} > {item.done ? ( ) : (
    )} {item.label} ); })}
{progress === 100 && ( {t('common.getStarted')} )}
); } /* ---------- Main Onboarding Flow ---------- */ function OnboardingFlow({ onComplete, className }: OnboardingFlowProps) { const { dir } = useI18n(); const [phase, setPhase] = useState('welcome'); const [direction, setDirection] = useState(1); const [role, setRole] = useState(null); const [industry, setIndustry] = useState(null); const goTo = useCallback((next: Phase) => { const order: Phase[] = ['welcome', 'firstValue', 'checklist']; setDirection(order.indexOf(next) > order.indexOf(phase) ? 1 : -1); setPhase(next); }, [phase]); const phases: Phase[] = ['welcome', 'firstValue', 'checklist']; const currentIdx = phases.indexOf(phase); return (
{/* Phase indicators */}
{phases.map((p, i) => (
))}
{/* Content */} {phase === 'welcome' && ( goTo('firstValue')} /> )} {phase === 'firstValue' && ( goTo('checklist')} /> )} {phase === 'checklist' && ( )}
); } export { OnboardingFlow }; export type { OnboardingFlowProps };