"use client"; import { useState } from "react"; import { motion, AnimatePresence } from "framer-motion"; interface Props { items: string[]; onXP: (amount: number) => void; } export default function HealthChecklist({ items, onXP }: Props) { const [checked, setChecked] = useState(new Array(items.length).fill(false)); const [floatingXP, setFloatingXP] = useState<{ id: number; x: number } | null>(null); const toggle = (i: number) => { if (checked[i]) return; const newChecked = [...checked]; newChecked[i] = true; setChecked(newChecked); onXP(10); setFloatingXP({ id: Date.now(), x: Math.random() * 60 + 20 }); setTimeout(() => setFloatingXP(null), 1000); }; const doneCount = checked.filter(Boolean).length; return (
{/* Progress bar */}
{doneCount}/{items.length}
{/* Floating XP */} {floatingXP && ( +10 XP ⭐ )} {/* Items */}
{items.map((item, i) => ( toggle(i)} className="flex items-center gap-3 p-3 rounded-xl cursor-pointer transition-all" style={{ background: checked[i] ? "rgba(34,197,94,0.08)" : "rgba(255,255,255,0.03)", border: checked[i] ? "1px solid rgba(34,197,94,0.3)" : "1px solid #334155", }} whileTap={{ scale: 0.97 }}> {checked[i] ? "✓" : ""} {item} {!checked[i] && ( +10 XP )} ))}
{doneCount === items.length && ( 🎉 शाबाश! सभी काम पूरे हो गए! (All done!) )}
); }