import React, { useEffect, useState } from 'react'; import { createPortal } from 'react-dom'; import { Task, TaskPriority } from '../types'; import { useLanguage } from '../i18n/LanguageContext'; import { MessageKey } from '../i18n/translations'; interface TaskCompleteModalProps { task: Task; level: number; onClose: () => void; } const ENCOURAGE_KEYS: Record = { high: ['encourageHigh1', 'encourageHigh2', 'encourageHigh3', 'encourageHigh4'], medium: ['encourageMid1', 'encourageMid2', 'encourageMid3', 'encourageMid4'], low: ['encourageLow1', 'encourageLow2', 'encourageLow3', 'encourageLow4'], }; const LEVEL_KEYS: Record = { 0: 'levelPhase', 1: 'levelTask', 2: 'levelSubtask', }; const EMOJIS_BY_LEVEL: Record = { 0: ['🏆', '🎊', '🎉', '🥇'], 1: ['⭐', '✨', '💫', '🌟'], 2: ['👍', '👏', '💪', '🎯'], }; const TaskCompleteModal: React.FC = ({ task, level, onClose }) => { const { t } = useLanguage(); const [visible, setVisible] = useState(false); useEffect(() => { requestAnimationFrame(() => setVisible(true)); const timer = setTimeout(() => handleClose(), 4000); return () => clearTimeout(timer); }, []); const handleClose = () => { setVisible(false); setTimeout(onClose, 300); }; const encouragePool = ENCOURAGE_KEYS[task.priority] || ENCOURAGE_KEYS.medium; const encouragement = t(encouragePool[(task.priority.charCodeAt(0) + level) % encouragePool.length]); const levelLabel = t(LEVEL_KEYS[level] || 'levelTask'); const emojis = EMOJIS_BY_LEVEL[level] || EMOJIS_BY_LEVEL[2]; const mainEmoji = emojis[Math.floor(Math.random() * emojis.length)]; return createPortal(
e.stopPropagation()} > {/* Confetti strip */}
{['#f59e0b', '#ef4444', '#3b82f6', '#10b981', '#8b5cf6', '#ec4899', '#f97316'].map((c, i) => (
))}
{/* Emoji with bounce */}
{mainEmoji}
{/* Level badge */} {t('levelDone', { label: levelLabel })} {/* Task title */}

{task.title}

{/* Encouragement */}

{encouragement}

{/* Progress ring */}
✓ {t('completed')}
{/* Close button */}
{/* Floating particles */}
{Array.from({ length: 12 }).map((_, i) => (
))}
, document.body ); }; export default TaskCompleteModal;