{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "chat-confirmation",
  "type": "registry:ui",
  "title": "Chat Confirmation",
  "description": "Asks someone to approve or decline an agent’s action.",
  "categories": [
    "ai-&-chat"
  ],
  "dependencies": [
    "@hugeicons/core-free-icons@4.4.0",
    "@hugeicons/react@1.1.10"
  ],
  "registryDependencies": [
    "https://sprout.tulipfarm.ai/r/sprout-base.json",
    "https://sprout.tulipfarm.ai/r/button.json",
    "https://sprout.tulipfarm.ai/r/review-card.json",
    "https://sprout.tulipfarm.ai/r/spinner.json"
  ],
  "files": [
    {
      "path": "registry/sprout/components/ui/chat-confirmation.tsx",
      "type": "registry:ui",
      "target": "components/ui/chat-confirmation.tsx",
      "content": "'use client';\n\nimport { useEffect, useRef, type ComponentProps, type ReactNode } from 'react';\nimport { ShieldUserIcon } from '@/lib/sprout/icons/shield-user-icon';\nimport { cn } from '@/lib/sprout/classes';\nimport { Button } from '@/components/ui/button';\nimport { ReviewCard, ReviewRow, ReviewRows, type ReviewCardBadge } from '@/components/ui/review-card';\nimport { Spinner } from '@/components/ui/spinner';\n\nexport const chatConfirmationStateNames = [\n  'pending',\n  'submitting',\n  'approved',\n  'rejected',\n  'expired',\n  'cancelled',\n  'error',\n] as const;\n\nexport type ChatConfirmationDecision = 'approve' | 'reject';\n\nexport type ConfirmationState =\n  | { kind: 'pending' }\n  | { kind: 'submitting'; decision: ChatConfirmationDecision }\n  | { kind: 'approved' }\n  | { kind: 'rejected' }\n  | { kind: 'expired' }\n  | { kind: 'cancelled' }\n  | { kind: 'error'; message: string };\n\nexport type ChatConfirmationDetail = { label: string; value: string };\n\nexport interface ChatConfirmationProps extends Omit<ComponentProps<'div'>, 'title' | 'children'> {\n  title: string;\n  description: string;\n  details: readonly ChatConfirmationDetail[];\n  state: ConfirmationState;\n  onDecision: (decision: ChatConfirmationDecision) => void;\n  disabled?: boolean | undefined;\n  approveLabel?: ReactNode;\n}\n\nconst settledKinds = new Set<ConfirmationState['kind']>(['approved', 'rejected', 'expired', 'cancelled']);\n\nconst badges: Record<ConfirmationState['kind'], ReviewCardBadge> = {\n  pending: { label: 'Approval required', variant: 'warning' },\n  submitting: { label: 'Approval required', variant: 'warning' },\n  error: { label: 'Approval required', variant: 'warning' },\n  approved: { label: 'Approved', variant: 'info' },\n  rejected: { label: 'Declined', variant: 'secondary' },\n  expired: { label: 'Expired', variant: 'secondary' },\n  cancelled: { label: 'Cancelled', variant: 'secondary' },\n};\n\nconst outcomes: Partial<Record<ConfirmationState['kind'], string>> = {\n  approved: 'Approval recorded. This does not confirm the action has completed.',\n  rejected: 'The proposed action was declined.',\n  expired: 'This approval expired. No approval was granted.',\n  cancelled: 'This approval was cancelled. No approval was granted.',\n};\n\nexport function ChatConfirmation({\n  title,\n  description,\n  details,\n  state,\n  onDecision,\n  disabled = false,\n  approveLabel = 'Approve action',\n  className,\n  ...props\n}: ChatConfirmationProps) {\n  const done = settledKinds.has(state.kind);\n  const section = useRef<HTMLDivElement>(null);\n  const result = useRef<HTMLParagraphElement>(null);\n  const submittedHere = useRef(false);\n  useEffect(() => {\n    if (state.kind === 'submitting') submittedHere.current = section.current?.contains(document.activeElement) ?? false;\n    if (done && submittedHere.current) {\n      result.current?.focus();\n      submittedHere.current = false;\n    }\n  }, [done, state.kind]);\n  const submitting = state.kind === 'submitting';\n  const busy = (decision: ChatConfirmationDecision) => state.kind === 'submitting' && state.decision === decision;\n  const outcome = outcomes[state.kind];\n  return (\n    <div\n      ref={section}\n      data-slot=\"chat-confirmation\"\n      data-state={state.kind}\n      {...props}\n      className={cn('sprout-chat-confirmation', className)}\n    >\n      <ReviewCard\n        icon={<ShieldUserIcon size=\"md\" />}\n        title={title}\n        badge={badges[state.kind]}\n        settled={done}\n        status={\n          state.kind === 'error' || outcome ? (\n            <>\n              {state.kind === 'error' && (\n                <p role=\"alert\" className=\"sprout-chat-confirmation-error\">\n                  {state.message}\n                </p>\n              )}\n              {outcome && (\n                <p ref={result} tabIndex={-1} role=\"status\" className=\"sprout-chat-confirmation-result\">\n                  {outcome}\n                </p>\n              )}\n            </>\n          ) : undefined\n        }\n        actions={\n          done ? undefined : (\n            <>\n              <Button\n                disabled={disabled || submitting}\n                aria-busy={busy('approve')}\n                onClick={() => onDecision('approve')}\n              >\n                {busy('approve') && <Spinner aria-hidden=\"true\" />}\n                {approveLabel}\n              </Button>\n              <Button\n                variant=\"ghost\"\n                disabled={disabled || submitting}\n                aria-busy={busy('reject')}\n                onClick={() => onDecision('reject')}\n              >\n                {busy('reject') && <Spinner aria-hidden=\"true\" />}\n                Decline\n              </Button>\n            </>\n          )\n        }\n      >\n        <p className=\"sprout-chat-confirmation-description\">{description}</p>\n        <ReviewRows>\n          {details.map(detail => (\n            <ReviewRow key={detail.label} label={detail.label}>\n              {detail.value}\n            </ReviewRow>\n          ))}\n        </ReviewRows>\n      </ReviewCard>\n    </div>\n  );\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/create-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/create-icon.tsx",
      "content": "import { HugeiconsIcon, type IconSvgElement } from '@hugeicons/react';\nimport type { ReactElement, Ref, SVGProps } from 'react';\n\nexport const iconSizes = {\n  xs: 12,\n  sm: 14,\n  md: 16,\n  lg: 18,\n  xl: 20,\n  '2xl': 24,\n} as const;\n\nexport type IconSize = keyof typeof iconSizes;\n\nexport const iconStrokeWidth = 1.5;\n\nexport type IconProps = Omit<SVGProps<SVGSVGElement>, 'ref'> & {\n  size?: IconSize | number;\n  ref?: Ref<SVGSVGElement>;\n};\n\nexport type IconComponent = (props: IconProps) => ReactElement;\n\nexport function createIcon(glyph: IconSvgElement, name: string): IconComponent {\n  const Icon = ({ size = '2xl', strokeWidth = iconStrokeWidth, ...props }: IconProps) => (\n    <HugeiconsIcon\n      icon={glyph}\n      size={typeof size === 'number' ? size : iconSizes[size]}\n      strokeWidth={Number(strokeWidth)}\n      {...props}\n    />\n  );\n  Icon.displayName = name;\n  return Icon;\n}\n"
    },
    {
      "path": "registry/sprout/lib/sprout/icons/shield-user-icon.tsx",
      "type": "registry:lib",
      "target": "lib/sprout/icons/shield-user-icon.tsx",
      "content": "import { ShieldUserIcon as glyph } from '@hugeicons/core-free-icons';\nimport { createIcon } from '@/lib/sprout/icons/create-icon';\n\nexport const ShieldUserIcon = /* @__PURE__ */ createIcon(glyph, 'ShieldUserIcon');\n"
    }
  ],
  "css": {
    "@layer components": {
      ".sprout-chat-confirmation": {
        "width": "100%",
        "min-width": "0"
      },
      ".sprout-chat-confirmation-description, .sprout-chat-confirmation-result": {
        "color": "var(--sprout-muted)",
        "font-size": "var(--sprout-text-sm)",
        "overflow-wrap": "anywhere",
        "margin": "0",
        "line-height": "1.25rem"
      },
      ".sprout-chat-confirmation-error": {
        "color": "var(--sprout-danger)",
        "font-size": "var(--sprout-text-sm)",
        "overflow-wrap": "anywhere",
        "margin": "0",
        "line-height": "1.25rem"
      },
      ".sprout-chat-confirmation-result": {
        "border-radius": "var(--sprout-radius-control)",
        "outline": "none"
      },
      ".sprout-chat-confirmation-result:focus-visible": {
        "outline": "var(--sprout-focus-width) solid var(--sprout-focus-ring)",
        "outline-offset": "0"
      }
    }
  },
  "docs": "Docs and examples: https://sprout.tulipfarm.ai/components/chat-confirmation/",
  "meta": {
    "source": "packages/sprout/src/components/chat-confirmation.tsx"
  }
}
