{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "confirm-action",
  "type": "registry:component",
  "description": "A confirmation dialog that wraps an async action with loading state",
  "registryDependencies": [
    "alert-dialog",
    "https://kaui-shadcn-registry.vercel.app/r/async-button.json"
  ],
  "files": [
    {
      "type": "registry:component",
      "target": "components/ui/confirm-action.tsx",
      "path": "src/registry/base/confirm-action/components/confirm-action.tsx",
      "content": "import {\n  AlertDialog,\n  AlertDialogCancel,\n  AlertDialogContent,\n  AlertDialogDescription,\n  AlertDialogFooter,\n  AlertDialogHeader,\n  AlertDialogMedia,\n  AlertDialogTitle,\n  AlertDialogTrigger,\n} from \"@/components/ui/alert-dialog\";\nimport { type ComponentProps, type ReactNode } from \"react\";\nimport { Button } from \"@/components/ui/button\";\nimport {\n  AsyncButton,\n  type AsyncButtonProps,\n} from \"@/components/ui/async-button\";\nimport { useControlledState } from \"@/hooks/use-controlled-state\";\n\ninterface ConfirmActionProps<TData = unknown, TError = unknown> extends Omit<\n  AsyncButtonProps<TData, TError, []>,\n  \"title\"\n> {\n  title?: ReactNode;\n  description?: ReactNode;\n  cancelText?: ReactNode;\n  confirmText?: ReactNode;\n  confirmVariant?: ComponentProps<typeof Button>[\"variant\"];\n  size?: ComponentProps<typeof AlertDialogContent>[\"size\"];\n  media?: ReactNode;\n  /** Controlled open state. Provide alongside `onOpenChange` to manage the dialog externally. */\n  open?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  /** Trigger element. Omit when controlling `open` externally. */\n  children?: ReactNode;\n}\n\n/**\n * Guards inreversible actions behind a confirm dialog\n *\n * **Required:** `action`\n */\nexport function ConfirmAction<TData = unknown, TError = unknown>({\n  action,\n  title = \"Are you sure?\",\n  description = \"This action cannot be undone.\",\n  cancelText = \"Cancel\",\n  confirmText = \"Continue\",\n  confirmVariant = \"default\",\n  size,\n  media,\n  loadingText,\n  onSuccess,\n  onError,\n  onSettled,\n  open: openProp,\n  onOpenChange,\n  children,\n  ...props\n}: ConfirmActionProps<TData, TError>) {\n  const [open, setOpen] = useControlledState({\n    value: openProp,\n    defaultValue: false,\n    onChange: onOpenChange,\n  });\n\n  return (\n    <AlertDialog open={open} onOpenChange={setOpen}>\n      {children && <AlertDialogTrigger asChild>{children}</AlertDialogTrigger>}\n\n      <AlertDialogContent size={size}>\n        <AlertDialogHeader>\n          {media && <AlertDialogMedia>{media}</AlertDialogMedia>}\n          <AlertDialogTitle>{title}</AlertDialogTitle>\n          <AlertDialogDescription>{description}</AlertDialogDescription>\n        </AlertDialogHeader>\n\n        <AlertDialogFooter>\n          <AlertDialogCancel>{cancelText}</AlertDialogCancel>\n          <AsyncButton\n            variant={confirmVariant}\n            action={action}\n            loadingText={loadingText ?? confirmText}\n            onSuccess={(data, args) => {\n              onSuccess?.(data, args);\n              setOpen(false);\n            }}\n            onError={onError}\n            onSettled={onSettled}\n            {...props}\n          >\n            {confirmText}\n          </AsyncButton>\n        </AlertDialogFooter>\n      </AlertDialogContent>\n    </AlertDialog>\n  );\n}\n"
    }
  ]
}