{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reaction-clock",
  "title": "Reaction clock",
  "description": "Wait for the cue and try to beat your fastest reaction time.",
  "dependencies": [
    "lucide-react@1.73.0"
  ],
  "registryDependencies": [
    "https://www.cyberspec.dev/r/recipe-layout.json",
    "https://www.cyberspec.dev/r/badge.json",
    "https://www.cyberspec.dev/r/button.json",
    "https://www.cyberspec.dev/r/readout.json"
  ],
  "files": [
    {
      "path": "registry/cyber/recipes/reaction-clock.tsx",
      "content": "\"use client\"\n\nimport { useEffect, useRef, useState } from \"react\"\nimport { Timer } from \"lucide-react\"\nimport { Badge } from \"@/registry/cyber/ui/badge\"\nimport { Button } from \"@/registry/cyber/ui/button\"\nimport { Readout } from \"@/registry/cyber/ui/readout\"\nimport \"./recipe-layout.css\"\n\ntype Phase = \"idle\" | \"waiting\" | \"ready\" | \"early\" | \"scored\"\n\nexport default function ReactionClock() {\n  const [phase, setPhase] = useState<Phase>(\"idle\")\n  const [last, setLast] = useState(0)\n  const [best, setBest] = useState<number>()\n  const start = useRef(0)\n  useEffect(() => {\n    if (phase !== \"waiting\") return\n    const timeout = window.setTimeout(() => {\n      start.current = performance.now()\n      setPhase(\"ready\")\n    }, 1500 + Math.random() * 2000)\n    return () => clearTimeout(timeout)\n  }, [phase])\n  function press() {\n    if (phase === \"waiting\") return setPhase(\"early\")\n    if (phase !== \"ready\") return setPhase(\"waiting\")\n    const time = Math.round(performance.now() - start.current)\n    setLast(time)\n    setBest(best === undefined ? time : Math.min(best, time))\n    setPhase(\"scored\")\n  }\n  const cues = { idle: \"Ready to start\", waiting: \"Wait for the cue\", ready: \"Tap now!\", early: \"Too soon. Try again.\", scored: `Reaction time · ${last} ms` }\n  return (\n    <div className=\"sink-stack\">\n      <div className=\"sink-between\"><span className=\"sink-label\">Reflex test</span><Badge tone=\"mute\">Best · {best === undefined ? \"—\" : `${best} ms`}</Badge></div>\n      <Readout label=\"Last time\" value={last} unit=\"ms\" size=\"lg\" />\n      <p role=\"status\" className=\"sink-note\">{cues[phase]}</p>\n      <Button size=\"lg\" tone={phase === \"ready\" ? \"flag\" : \"secondary\"} onClick={press}><Timer aria-hidden />{phase === \"ready\" ? \"Tap now\" : phase === \"waiting\" ? \"Wait…\" : phase === \"idle\" ? \"Start round\" : \"Play again\"}</Button>\n    </div>\n  )\n}\n",
      "type": "registry:component",
      "target": "@components/recipes/reaction-clock.tsx"
    }
  ],
  "categories": [
    "recipe",
    "arcade"
  ],
  "type": "registry:component"
}
