{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "approval-prompt",
  "dependencies": [],
  "registryDependencies": [
    "https://turnui.xyz/r/turn-button.json",
    "utils"
  ],
  "files": [
    {
      "path": "src/registry/ui/approval-prompt.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { Button } from \"./turn-button\";\n\n/** Human-in-the-loop gate: the agent wants to do something and needs a yes/no. */\nconst riskStyle = {\n  low: { bar: \"bg-emerald-500\", text: \"text-emerald-700 dark:text-emerald-400\", label: \"Low risk\" },\n  medium: { bar: \"bg-amber-500\", text: \"text-amber-700 dark:text-amber-400\", label: \"Medium risk\" },\n  high: { bar: \"bg-red-500\", text: \"text-red-700 dark:text-red-400\", label: \"High risk\" },\n} as const;\n\nexport function ApprovalPrompt({\n  title,\n  description,\n  details,\n  status = \"pending\",\n  risk,\n  autoFocus = false,\n  onApprove,\n  onDeny,\n  className,\n}: {\n  title: string;\n  description?: string;\n  details?: React.ReactNode;\n  status?: \"pending\" | \"approved\" | \"denied\";\n  /** How consequential the action is. Shown as a text label and a coloured edge. */\n  risk?: \"low\" | \"medium\" | \"high\";\n  /** Move focus into the prompt when it appears (use when it arrives mid-conversation). */\n  autoFocus?: boolean;\n  onApprove?: () => void;\n  onDeny?: () => void;\n  className?: string;\n}) {\n  const ref = React.useRef<HTMLDivElement>(null);\n\n  React.useEffect(() => {\n    if (autoFocus && status === \"pending\") ref.current?.focus();\n  }, [autoFocus, status]);\n\n  // Approve/Deny unmount once decided; keep keyboard focus in the prompt instead of losing it to <body>.\n  const wasPending = React.useRef(status === \"pending\");\n  React.useEffect(() => {\n    if (wasPending.current && status !== \"pending\" && document.activeElement === document.body) {\n      ref.current?.focus();\n    }\n    wasPending.current = status === \"pending\";\n  }, [status]);\n\n  const edge = status === \"approved\" ? \"bg-emerald-500\" : status === \"denied\" ? \"bg-red-500\" : risk ? riskStyle[risk].bar : \"bg-foreground/60\";\n\n  return (\n    <div\n      ref={ref}\n      role=\"alertdialog\"\n      aria-modal=\"false\"\n      aria-label={title}\n      tabIndex={-1}\n      className={cn(\"relative overflow-hidden rounded border bg-muted/20 py-3 pl-4 pr-3 outline-none focus-visible:border-foreground/50\", className)}\n    >\n      <span aria-hidden className={cn(\"absolute inset-y-0 left-0 w-0.5\", edge)} />\n      <div className=\"flex items-center gap-2 font-mono text-[11px] uppercase tracking-wider text-muted-foreground\">\n        <span aria-live=\"polite\">{status === \"pending\" ? \"Needs approval\" : status === \"approved\" ? \"Approved\" : \"Denied\"}</span>\n        {status === \"pending\" && risk && <span className={riskStyle[risk].text}>· {riskStyle[risk].label}</span>}\n      </div>\n      <div className=\"mt-1.5 text-sm font-medium\">{title}</div>\n      {description && <p className=\"mt-0.5 text-sm text-muted-foreground\">{description}</p>}\n      {details && <div className=\"mt-2.5 rounded-sm border bg-background/60 p-2.5 font-mono text-xs\">{details}</div>}\n      {status === \"pending\" && (\n        <div className=\"mt-3 flex items-center gap-2\">\n          <Button size=\"sm\" variant=\"primary\" onClick={onApprove}>Approve</Button>\n          <Button size=\"sm\" variant=\"outline\" onClick={onDeny}>Deny</Button>\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}