import type { ReactNode } from 'react'; import { useAuth } from '@/hooks/useAuth'; import { useLearningJourney } from '@/hooks/useLearningJourney'; import { useCurrentSession } from '@/hooks/useCurrentSession'; import { PROGRAM_SESSION_COUNT } from '@/data/program/sessions'; import { getProgramProgress } from '@/services/programService'; import { Progress } from '@/components/ui/progress'; import { Navigate, useNavigate } from 'react-router-dom'; import { Check, ChevronLeft, Lock, NotebookPen } from 'lucide-react'; import { cn } from '@/lib/utils'; import { StaggeredList, StaggerItem, AnimationWrapper } from '@/components/motion'; import { motion } from 'framer-motion'; import { fastTransition } from '@/lib/motion'; import { CourseStatusSkeleton } from '@/components/skeletons'; import { Button } from '@/components/ui/button'; type StepState = 'open' | 'locked' | 'done'; /** * Course Status surface (profile menu → وضعیت دوره). * Journey status only — no settings, scores, or assessment results. */ export default function AccountPage() { const { effectiveUserId, isGuest, guestSessionHydrated, user } = useAuth(); const { progress, loading, permissions } = useLearningJourney(effectiveUserId ?? undefined); const { currentSession, isProgramComplete, programProgress, progressLoading } = useCurrentSession(effectiveUserId); const navigate = useNavigate(); const usernameLabel = isGuest ? 'مهمان' : user?.email?.trim() || null; if (!guestSessionHydrated || loading || progressLoading) { return ; } if (!effectiveUserId) { return ; } const cachedProgress = getProgramProgress(effectiveUserId); const effectiveProgramProgress = programProgress ?? cachedProgress; const completedSessions = effectiveProgramProgress.completedSessions.length; const programDone = isProgramComplete || Boolean(effectiveProgramProgress.completedAt) || completedSessions >= PROGRAM_SESSION_COUNT; const progressPercent = programDone ? 100 : Math.round((completedSessions / PROGRAM_SESSION_COUNT) * 100); const preDone = Boolean(progress?.pre_test_completed_at); const reachedFinalSession = Boolean(progress?.training_completed_at) || completedSessions >= PROGRAM_SESSION_COUNT - 1 || programDone; const trainingDone = Boolean(progress?.training_completed_at) || programDone; const postDone = Boolean(progress?.post_test_completed_at); const displaySessionOrder = currentSession?.order ?? (programDone ? PROGRAM_SESSION_COUNT : Math.max(effectiveProgramProgress.currentSessionOrder || 1, 1)); const preState: StepState = preDone ? 'done' : 'open'; const trainingState: StepState = !permissions.canOpenTraining ? 'locked' : trainingDone ? 'done' : 'open'; const postState: StepState = postDone ? 'done' : permissions.canTakePostTest || (reachedFinalSession && preDone && !postDone) ? 'open' : 'locked'; return (

وضعیت دوره

{usernameLabel && (

نام کاربری:{' '} {usernameLabel}

)} {!isGuest ? ( ) : null}
navigate('/assessment/pre')} lockedHint={preDone ? 'انجام شده — قابل تکرار نیست' : undefined} > {preDone ? ( ) : (

برای شروع مسیر، پیش‌آزمون را انجام دهید

)}
navigate('/chat')} lockedHint={ trainingDone ? 'دوره تکمیل شده' : 'پس از انجام پیش‌آزمون فعال می‌شود' } > {trainingDone ? ( ) : !permissions.canOpenTraining ? (

پس از انجام پیش‌آزمون فعال می‌شود

) : (

جلسه {displaySessionOrder} از {PROGRAM_SESSION_COUNT}

{progressPercent}٪
)}
navigate('/assessment/post')} lockedHint={ postDone ? 'انجام شده — قابل تکرار نیست' : 'پس از رسیدن به جلسه پایانی فعال می‌شود' } > {postState === 'done' && } {postState === 'open' && (

آماده انجام

)} {postState === 'locked' && (

پس از رسیدن به جلسه پایانی فعال می‌شود

)}
); } function StatusRow({ title, children, state, onOpen, lockedHint, }: { title: string; children: ReactNode; state: StepState; onOpen: () => void; lockedHint?: string; }) { const isInteractive = state === 'open'; const content = (

{title}

{children}
{isInteractive ? ( ) : ( )}
); if (isInteractive) { return ( {content} ); } return (
{content}
); } function StatusDone({ label }: { label: string }) { return (

{label}

); }