"use client"; /** * LevelUpOverlay — full-screen celebration overlay that auto-dismisses. * * Usage: * setShowLevelUp(false)} * /> * * Auto-dismisses after 3 seconds. Click anywhere to dismiss early. */ import { useEffect, useCallback } from "react"; import { motion, AnimatePresence } from "framer-motion"; import { CATEGORY_COLORS, CATEGORY_LABELS, type Category } from "@/config/xp"; import { nativeHaptics } from "@/lib/native"; export interface LevelUpOverlayProps { show: boolean; level: number; title?: string; // new title if unlocked at this level category: Category; onDismiss: () => void; autoDismissMs?: number; // default 3000 } /** One CSS-only particle — absolutely positioned, randomised via inline style */ function Particle({ accent, delay, i }: { accent: string; delay: number; i: number }) { // Distribute particles around the screen using index const angle = (i / 20) * 360; const distance = 120 + (i % 5) * 40; // 120–280 px const dx = Math.round(Math.cos((angle * Math.PI) / 180) * distance); const dy = Math.round(Math.sin((angle * Math.PI) / 180) * distance); const size = 6 + (i % 4) * 3; // 6–15 px const colors = [accent, "#ffffff", "#f59e0b", "#22c55e", "#8b5cf6"]; const color = colors[i % colors.length]; return ( ); } export function LevelUpOverlay({ show, level, title, category, onDismiss, autoDismissMs = 3000, }: LevelUpOverlayProps) { const dismiss = useCallback(() => onDismiss(), [onDismiss]); useEffect(() => { if (!show) return; // Trigger heavy haptic on level-up nativeHaptics.levelUp(); const t = setTimeout(dismiss, autoDismissMs); return () => clearTimeout(t); }, [show, dismiss, autoDismissMs]); const accent = CATEGORY_COLORS[category]; const catLabel = CATEGORY_LABELS[category]; return ( {show && ( {/* Particle field */}
{Array.from({ length: 20 }).map((_, i) => ( ))}
{/* Content card */} e.stopPropagation()} > {/* Glow ring */} {/* Category badge */}

{catLabel}

{/* ⬆ icon */} ⬆ {/* Level number */} {level}

Level Up!

{title && ( New Title: {title} )}

Click anywhere to continue

)}
); }