"use client" import { useState, useCallback } from "react" import { motion, AnimatePresence } from "framer-motion" import { GatoMascota } from "@/components/child/gato-mascota" import { CuisenaireRod, rodColors } from "@/components/child/cuisenaire-rod" import TemporizadorVisual from "@/components/child/temporizador-visual" import { speak } from "@/lib/speech" import { getRods } from "@/lib/pedagogia/cuisenaire" import { createCPAState, advanceStage } from "@/lib/pedagogia/cpa-progression" import { generateCPAItems, speakCPAInstruction } from "@/components/child/cpa-exercise" type CPAStage = "concrete" | "pictoric" | "abstract" export default function NumerosPage() { const [currentValue, setCurrentValue] = useState(1) const [stage, setStage] = useState("concrete") const [running, setRunning] = useState(true) const [sessionComplete, setSessionComplete] = useState(false) const [score, setScore] = useState(0) const [tappedItems, setTappedItems] = useState([]) const rods = getRods(10) const cpaItems = generateCPAItems(currentValue, stage) const startValue = useCallback( (value: number) => { setCurrentValue(value) const newStage = value <= 3 ? "concrete" : value <= 6 ? "pictoric" : "abstract" setStage(newStage) setTappedItems([]) speakCPAInstruction(value, newStage) }, [], ) const handleItemTap = useCallback( (id: number) => { setTappedItems((prev) => { const next = [...prev, id] if (next.length === currentValue) { setScore((s) => s + 1) if (currentValue >= 5) { setSessionComplete(true) setRunning(false) } else { const nextValue = currentValue + 1 setCurrentValue(nextValue) const newStage: CPAStage = nextValue <= 3 ? "concrete" : nextValue <= 6 ? "pictoric" : "abstract" setStage(newStage) setTappedItems([]) setTimeout(() => speakCPAInstruction(nextValue, newStage), 500) } } return next }) }, [currentValue], ) if (sessionComplete) { return (

Puntuación: {score}/5

) } return (
{ setRunning(false) setSessionComplete(true) }} running={running} /> {/* Level indicator */}
{[1, 2, 3, 4, 5].map((n) => ( ))}
{/* CPA area */}
{stage === "concrete" && cpaItems.map((item) => ( handleItemTap(item.id)} className="text-4xl touch-target active:scale-110 transition-transform" whileTap={{ scale: 1.2 }} animate={ tappedItems.includes(item.id) ? { scale: 0.8, opacity: 0.5 } : { scale: 1, opacity: 1 } } > {item.emoji} ))} {stage === "pictoric" && (
{cpaItems.map((item, i) => ( {item.emoji} ))}
{[1, 2, 3, 4, 5].map((n) => ( ))}
)} {stage === "abstract" && (
{currentValue}

Tocá el número que ves arriba

{[1, 2, 3, 4, 5, 6, 7, 8, 9, 10].map((n) => ( ))}
)}
{/* Cuisenaire reference */}
{rods.slice(0, currentValue).map((rod) => ( ))}
) }