"use client" import { useState } from "react" import { useRouter } from "next/navigation" import { GatoMascota } from "@/components/child/gato-mascota" import { speak } from "@/lib/speech" const CHILD_ID_KEY = "edueasy_child_id" export default function ChildPairingPage() { const [code, setCode] = useState("") const [loading, setLoading] = useState(false) const [error, setError] = useState("") const [paired, setPaired] = useState(false) const router = useRouter() const handlePair = async (e: React.FormEvent) => { e.preventDefault() setLoading(true) setError("") const deviceFingerprint = `child-${navigator.userAgent.slice(0, 64)}` const res = await fetch("/api/pairing", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ pairingCode: code.toUpperCase(), deviceFingerprint, }), }) const data = await res.json() if (data.error) { setError(data.error) setLoading(false) return } localStorage.setItem(CHILD_ID_KEY, data.childId) setPaired(true) speak("¡Emparejado! Ahora podemos aprender juntos") } if (paired) { return (
) } return (
setCode(e.target.value.toUpperCase())} placeholder="Código" maxLength={8} className="w-full rounded-2xl border-2 border-primary bg-white px-6 py-4 text-center text-3xl tracking-[0.5em] uppercase font-display font-bold focus:outline-none focus:ring-4 focus:ring-primary/30" autoFocus /> {error &&

{error}

}
) }