{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "reasoning",
  "type": "registry:component",
  "title": "Reasoning",
  "description": "Collapsible Thought shell with shimmer trigger and scrollable body.",
  "registryDependencies": [
    "surfaces"
  ],
  "files": [
    {
      "path": "registry/tonic/reasoning/reasoning.tsx",
      "content": "\"use client\"\n\nimport {\n  createContext,\n  useCallback,\n  useContext,\n  useEffect,\n  useRef,\n  useState,\n  type PropsWithChildren,\n} from \"react\"\nimport { BrainIcon, ChevronDownIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { ShimmerLabel } from \"@/registry/tonic/lib/surfaces\"\n\ntype ReasoningContextValue = {\n  isOpen: boolean\n  isPreview: boolean\n  onOpenChange: (open: boolean) => void\n}\n\nconst ReasoningContext = createContext<ReasoningContextValue | null>(null)\n\nfunction useReasoningContext() {\n  const context = useContext(ReasoningContext)\n  if (!context) {\n    throw new Error(\"Reasoning components must be nested in ReasoningRoot\")\n  }\n  return context\n}\n\nexport type ReasoningRootProps = Omit<\n  React.ComponentProps<\"div\">,\n  \"children\"\n> &\n  PropsWithChildren<{\n    open?: boolean\n    onOpenChange?: (open: boolean) => void\n    defaultOpen?: boolean\n    streaming?: boolean\n  }>\n\nexport function ReasoningRoot({\n  open: controlledOpen,\n  onOpenChange: controlledOnOpenChange,\n  defaultOpen = false,\n  streaming,\n  className,\n  children,\n  ...props\n}: ReasoningRootProps) {\n  const [initialOpen] = useState(defaultOpen)\n  const [userOpen, setUserOpen] = useState<boolean | null>(null)\n  const isControlled = controlledOpen !== undefined\n  const isOpen = isControlled\n    ? controlledOpen\n    : (userOpen ?? (streaming || initialOpen))\n  const isPreview = streaming === true && isOpen\n  const onOpenChange = useCallback(\n    (open: boolean) => {\n      if (!isControlled) setUserOpen(open)\n      controlledOnOpenChange?.(open)\n    },\n    [controlledOnOpenChange, isControlled]\n  )\n\n  return (\n    <ReasoningContext.Provider value={{ isOpen, isPreview, onOpenChange }}>\n      <div\n        data-slot=\"reasoning-root\"\n        className={cn(\"w-full\", className)}\n        {...props}\n      >\n        {children}\n      </div>\n    </ReasoningContext.Provider>\n  )\n}\n\nexport type ReasoningTriggerProps = Omit<\n  React.ComponentProps<\"button\">,\n  \"children\"\n> & {\n  active?: boolean\n  duration?: number\n}\n\nexport function ReasoningTrigger({\n  active,\n  duration,\n  className,\n  onClick,\n  ...props\n}: ReasoningTriggerProps) {\n  const { isOpen, onOpenChange } = useReasoningContext()\n  const label = `Reasoning${duration ? ` (${duration}s)` : \"\"}`\n\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"reasoning-trigger\"\n      aria-expanded={isOpen}\n      aria-busy={active === true}\n      className={cn(\n        \"flex min-h-7 items-center gap-1.5 py-1 outline-none\",\n        className\n      )}\n      onClick={(event) => {\n        onClick?.(event)\n        onOpenChange(!isOpen)\n      }}\n      {...props}\n    >\n      <BrainIcon className=\"text-muted-foreground size-3.5\" />\n      <ShimmerLabel\n        active={active}\n        className=\"text-muted-foreground text-[15px] leading-6 tabular-nums\"\n      >\n        {label}\n      </ShimmerLabel>\n      <ChevronDownIcon\n        className={cn(\n          \"text-muted-foreground/55 size-3.5 transition-transform duration-200 motion-reduce:transition-none\",\n          !isOpen && \"-rotate-90\"\n        )}\n      />\n    </button>\n  )\n}\n\nexport type ReasoningContentProps = Omit<\n  React.ComponentProps<\"div\">,\n  \"children\"\n> &\n  PropsWithChildren\n\nexport function ReasoningContent({\n  className,\n  children,\n  ...props\n}: ReasoningContentProps) {\n  const { isOpen } = useReasoningContext()\n  if (!isOpen) return null\n  return (\n    <div\n      data-slot=\"reasoning-content\"\n      className={cn(\"overflow-hidden\", className)}\n      {...props}\n    >\n      {children}\n    </div>\n  )\n}\n\nexport type ReasoningTextProps = Omit<\n  React.ComponentProps<\"div\">,\n  \"children\"\n> &\n  PropsWithChildren\n\nexport function ReasoningText({\n  className,\n  children,\n  ...props\n}: ReasoningTextProps) {\n  const { isPreview } = useReasoningContext()\n  const scrollRef = useRef<HTMLDivElement>(null)\n\n  useEffect(() => {\n    if (!isPreview || !scrollRef.current) return\n    scrollRef.current.scrollTop = scrollRef.current.scrollHeight\n  }, [isPreview, children])\n\n  return (\n    <div\n      ref={scrollRef}\n      data-slot=\"reasoning-text\"\n      className={cn(\"max-h-64 overflow-y-auto py-2 ps-6\", className)}\n      {...props}\n    >\n      {typeof children === \"string\" || typeof children === \"number\" ? (\n        <p className=\"text-muted-foreground text-sm whitespace-pre-wrap\">\n          {children}\n        </p>\n      ) : (\n        children\n      )}\n    </div>\n  )\n}\n\nexport const Reasoning = {\n  Root: ReasoningRoot,\n  Trigger: ReasoningTrigger,\n  Content: ReasoningContent,\n  Text: ReasoningText,\n}\n",
      "type": "registry:component"
    }
  ]
}