import { useState } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { ChevronLeft } from 'lucide-react'; import { useNavigate } from 'react-router-dom'; import { Button } from '@/components/ui/button'; import { DIMENSION_CONFIGS, DIMENSION_ORDER, type DimensionConfig, getDescriptiveTitleForScore, } from '@/config/resultImages'; import { DimensionCard } from './DimensionCard'; import { SmoothTextAppearance } from '@/components/motion'; import type { AssessmentSubmission } from '@/services/assessmentService'; import type { DimensionName } from '@/lib/assessment/scoring/dimensions'; import { cn } from '@/lib/utils'; import { MOTION_EASE } from '@/lib/motion'; export interface AssessmentResultViewProps { phase: 'pre' | 'post'; currentSubmission: AssessmentSubmission; baselineSubmission?: AssessmentSubmission | null; onContinue?: () => void; continueLabel?: string; showActions?: boolean; } export function AssessmentResultView({ phase, currentSubmission, baselineSubmission, onContinue, continueLabel = 'مشاهده آموزشها و تمرینها', showActions = true, }: AssessmentResultViewProps) { const navigate = useNavigate(); const isPre = phase === 'pre'; const scores = currentSubmission.scores; const baselineScores = baselineSubmission?.scores; // Active step: 0, 1, 2, 3 = dimension steps; 4 = final summary screen const [currentStepIndex, setCurrentStepIndex] = useState(0); const [isTransitioning, setIsTransitioning] = useState(false); // Track revealed status for each dimension so it's preserved on back/forward const [revealed, setRevealed] = useState>({ efficacy: false, hope: false, resilience: false, optimism: false, }); const totalScore = scores.total; const maxTotalScore = 144; const totalPercent = Math.round( (Math.max(0, Math.min(maxTotalScore, totalScore)) / maxTotalScore) * 100 ); const hasComparison = Boolean( !isPre && baselineScores && typeof baselineScores.total === 'number' ); const totalDelta = hasComparison ? totalScore - (baselineScores?.total ?? 0) : 0; const currentDimensionKey = DIMENSION_ORDER[currentStepIndex]; const isSummaryStep = currentStepIndex === 4; const handleRevealCurrent = () => { if (currentDimensionKey) { setRevealed((prev) => ({ ...prev, [currentDimensionKey]: true })); } }; const handleNext = () => { if (isTransitioning) return; setIsTransitioning(true); setCurrentStepIndex((prev) => Math.min(prev + 1, 4)); window.setTimeout(() => setIsTransitioning(false), 220); }; const handlePrev = () => { if (isTransitioning) return; setIsTransitioning(true); setCurrentStepIndex((prev) => Math.max(prev - 1, 0)); window.setTimeout(() => setIsTransitioning(false), 220); }; const handleJumpToStep = (index: number) => { if (isTransitioning) return; const targetDimension = DIMENSION_ORDER[index]; if ( index < currentStepIndex || (index <= 3 && targetDimension && revealed[targetDimension]) || index === currentStepIndex ) { setIsTransitioning(true); setCurrentStepIndex(index); window.setTimeout(() => setIsTransitioning(false), 220); } }; const handleFinalContinue = () => { if (onContinue) { onContinue(); } else if (isPre) { navigate('/chat'); } else { navigate('/course-status'); } }; return (
{/* 1. Low-Height, Minimal 4-Segment Progress Indicator */}
{isSummaryStep ? 'جمع‌بندی نهایی' : `مؤلفه ${currentStepIndex + 1} از ۴`} {isSummaryStep ? 'کارنامه نهایی' : DIMENSION_CONFIGS[currentDimensionKey]?.titleFa}
{/* Clean, low-height segment bar */}
{DIMENSION_ORDER.map((dimKey, idx) => { const isCompleted = revealed[dimKey] && (currentStepIndex > idx || isSummaryStep); const isCurrent = currentStepIndex === idx; return (
{/* 2. Main Content (Dimension Card OR Final Summary) */}
{!isSummaryStep && currentDimensionKey ? ( /* Step-by-Step Dimension Card */ 0 ? handlePrev : undefined} isLastDimension={currentStepIndex === 3} /> ) : ( /* Final Summary Screen */ {/* Main Summary Glass Card */}
{/* Header Title */}

{isPre ? 'کارنامه اولیه سرمایه روان‌شناختی' : 'کارنامه نهایی دوره نویا'}

خلاصه وضعیت چهار مؤلفه شما

{/* Total Score Section */}
نمره کل آزمون:
{totalScore.toLocaleString('fa-IR')} از ۱۴۴
{hasComparison && baselineScores && (
پیش‌آزمون: {baselineScores.total.toLocaleString('fa-IR')} ➔ پس‌آزمون: {totalScore.toLocaleString('fa-IR')} 0 ? 'font-bold text-emerald-600 dark:text-emerald-400' : totalDelta < 0 ? 'font-bold text-amber-600 dark:text-amber-400' : 'text-muted-foreground' } > {totalDelta > 0 ? `+${totalDelta.toLocaleString('fa-IR')} رشد کل` : totalDelta < 0 ? `${totalDelta.toLocaleString('fa-IR')} تغییر` : 'بدون تغییر'}
)}
{/* 4-Dimension Comparative Bars (Simple & Readable) */}
{DIMENSION_ORDER.map((dimKey) => { const config: DimensionConfig = DIMENSION_CONFIGS[dimKey]; const dimScore = scores[dimKey]; const dimPercent = Math.round((dimScore / 36) * 100); return (
{config.titleFa} {getDescriptiveTitleForScore(dimKey, dimScore)}
); })}
{/* Non-diagnostic notice */}

این نتیجه بازتاب پاسخ‌های فعلی شماست و تشخیص قطعی روان‌شناختی نیست.

{/* Mandatory Closing Text */}

حالا تصویر روشن‌تری از چهار مؤلفه سرمایه روان‌شناختی خودت داری. {'\n\n'} این نتیجه، نقطه شروعیه برای شناخت بهتر خودت؛ نه تعریف کامل شخصیت تو. {'\n\n'} برای آشنایی بیشتر با این مؤلفه‌ها و تقویت اون‌ها، پیشنهاد می‌کنیم آموزش‌های نویا رو ببینی و تمرین‌های مرتبط رو انجام بدی.

{/* Single Prominent Button */} {showActions && (
{/* Subtle Secondary Back Control */}
)}
)}
); }