{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toast",
  "title": "Toast",
  "description": "Brief notifications shown with a toast() call and a Toaster mounted once, with variants, an optional action, swipe to dismiss and screen reader announcements.",
  "dependencies": [
    "@radix-ui/react-toast",
    "lucide-react"
  ],
  "registryDependencies": [
    "@corsair-ui/utils"
  ],
  "files": [
    {
      "path": "registry/default/ui/toast.tsx",
      "content": "\"use client\";\nimport * as ToastPrimitive from \"@radix-ui/react-toast\";\nimport { CircleAlertIcon, CircleCheckIcon, XIcon } from \"lucide-react\";\nimport { type ComponentProps, type ReactNode, useSyncExternalStore } from \"react\";\nimport { cn } from \"@/registry/default/lib/utils\";\n\ntype ToastVariant = \"default\" | \"success\" | \"destructive\";\n\ninterface ToastAction {\n  /** Visible text of the action button. */\n  label: string;\n  onClick: () => void;\n  /**\n   * Tells screen reader users how to do the same thing without the toast,\n   * since it may disappear before they reach it (\"Undo from the Trash page\").\n   */\n  altText: string;\n}\n\ninterface ToastOptions {\n  title?: ReactNode;\n  description?: ReactNode;\n  action?: ToastAction;\n  variant?: ToastVariant;\n  /** Milliseconds before it closes on its own. Overrides the Toaster's `duration`; `Infinity` keeps it open. */\n  duration?: number;\n}\n\ninterface ToastItem extends ToastOptions {\n  id: string;\n  /** False while the toast plays its exit animation, just before it is removed. */\n  open: boolean;\n}\n\ninterface ToastHandle {\n  id: string;\n  dismiss: () => void;\n  update: (options: ToastOptions) => void;\n}\n\n/** How many toasts are open at once; a new one closes the oldest. */\nconst MAX_VISIBLE = 3;\n/** How long a closed toast stays in the list so its exit animation can finish. */\nconst REMOVE_DELAY = 1000;\n\nlet toasts: ToastItem[] = [];\nlet counter = 0;\nconst listeners = new Set<() => void>();\nconst removeTimers = new Map<string, ReturnType<typeof setTimeout>>();\nconst EMPTY: ToastItem[] = [];\n\nfunction emit(next: ToastItem[]) {\n  toasts = next;\n  for (const listener of listeners) listener();\n}\n\nfunction subscribe(listener: () => void) {\n  listeners.add(listener);\n  return () => {\n    listeners.delete(listener);\n  };\n}\n\nfunction scheduleRemoval(id: string) {\n  if (removeTimers.has(id)) return;\n  removeTimers.set(\n    id,\n    setTimeout(() => {\n      removeTimers.delete(id);\n      emit(toasts.filter((item) => item.id !== id));\n    }, REMOVE_DELAY)\n  );\n}\n\nfunction dismiss(id?: string) {\n  const closing = toasts.filter((item) => item.open && (id === undefined || item.id === id));\n  if (closing.length === 0) return;\n  emit(toasts.map((item) => (closing.includes(item) ? { ...item, open: false } : item)));\n  for (const item of closing) scheduleRemoval(item.id);\n}\n\nfunction update(id: string, options: ToastOptions) {\n  emit(toasts.map((item) => (item.id === id ? { ...item, ...options } : item)));\n}\n\n/**\n * Shows a toast in the mounted `Toaster` and returns a handle to update or\n * dismiss it. Works anywhere, including outside React components.\n *\n * @example\n * const saved = toast({ title: \"Saved\", variant: \"success\" });\n * saved.update({ description: \"All changes are synced.\" });\n * toast.dismiss(); // closes every toast\n */\nfunction toast(options: ToastOptions): ToastHandle {\n  counter += 1;\n  const id = `toast-${counter}`;\n  const next = [...toasts, { ...options, id, open: true }];\n  emit(next);\n  // Keep at most MAX_VISIBLE open: close the oldest ones.\n  const open = next.filter((item) => item.open);\n  for (const item of open.slice(0, Math.max(0, open.length - MAX_VISIBLE))) dismiss(item.id);\n  return {\n    id,\n    dismiss: () => dismiss(id),\n    update: (changes) => update(id, changes),\n  };\n}\n\n/** Closes one toast by id, or every toast when called without one. */\ntoast.dismiss = dismiss;\n\n/** The current toasts, including ones that are closing. Re-renders when the list changes. */\nfunction useToasts(): ToastItem[] {\n  return useSyncExternalStore(\n    subscribe,\n    () => toasts,\n    () => EMPTY\n  );\n}\n\ntype ToasterPosition =\n  \"top-left\" | \"top-center\" | \"top-right\" | \"bottom-left\" | \"bottom-center\" | \"bottom-right\";\n\nconst viewportPosition: Record<ToasterPosition, string> = {\n  \"top-left\": \"top-0 left-0 flex-col-reverse\",\n  \"top-center\": \"top-0 left-1/2 -translate-x-1/2 flex-col-reverse\",\n  \"top-right\": \"top-0 right-0 flex-col-reverse\",\n  \"bottom-left\": \"bottom-0 left-0 flex-col\",\n  \"bottom-center\": \"bottom-0 left-1/2 -translate-x-1/2 flex-col\",\n  \"bottom-right\": \"bottom-0 right-0 flex-col\",\n};\n\nconst swipeDirection: Record<ToasterPosition, \"up\" | \"down\" | \"left\" | \"right\"> = {\n  \"top-left\": \"left\",\n  \"top-center\": \"up\",\n  \"top-right\": \"right\",\n  \"bottom-left\": \"left\",\n  \"bottom-center\": \"down\",\n  \"bottom-right\": \"right\",\n};\n\n// Full class names (not built from parts) so Tailwind finds them in the source.\nconst toastMotion: Record<ToasterPosition, string> = {\n  \"top-left\": \"data-[state=open]:slide-in-from-top-full data-[state=closed]:slide-out-to-left-full\",\n  \"top-center\":\n    \"data-[state=open]:slide-in-from-top-full data-[state=closed]:slide-out-to-top-full\",\n  \"top-right\":\n    \"data-[state=open]:slide-in-from-top-full data-[state=closed]:slide-out-to-right-full\",\n  \"bottom-left\":\n    \"data-[state=open]:slide-in-from-bottom-full data-[state=closed]:slide-out-to-left-full\",\n  \"bottom-center\":\n    \"data-[state=open]:slide-in-from-bottom-full data-[state=closed]:slide-out-to-bottom-full\",\n  \"bottom-right\":\n    \"data-[state=open]:slide-in-from-bottom-full data-[state=closed]:slide-out-to-right-full\",\n};\n\nconst toastVariant: Record<ToastVariant, string> = {\n  default: \"bg-background text-foreground border\",\n  success: \"bg-background text-foreground border-success/50 border\",\n  destructive: \"bg-destructive text-destructive-foreground border-destructive border\",\n};\n\ninterface ToasterProps extends Omit<ComponentProps<typeof ToastPrimitive.Viewport>, \"label\"> {\n  /** Corner or edge of the screen the toasts stack in. */\n  position?: ToasterPosition;\n  /** Milliseconds before a toast closes on its own. */\n  duration?: number;\n  /**\n   * Accessible name of the notifications region. `{hotkey}` is replaced by the\n   * keyboard shortcut that moves focus to it (\"Notifications ({hotkey})\").\n   */\n  label?: string;\n  /** Accessible name of each toast's close button. */\n  closeLabel?: string;\n  /** Word screen readers say before each announced toast. */\n  toastLabel?: string;\n}\n\n/**\n * Renders the toasts created with `toast()`. Mount it once, near the root of\n * the app. At most three are open at a time. Each toast is announced to screen\n * readers when it appears (destructive ones interrupt, others wait their turn);\n * F8 moves focus to the stack, Tab reaches the action and close buttons, and\n * Escape closes the focused toast. The timer pauses while the pointer is over\n * a toast, while one has focus, and while the window is in the background.\n * Toasts can be swiped away towards the nearest edge. With reduced motion they\n * appear and disappear without sliding.\n *\n * @example\n * <Toaster position=\"top-center\" />\n * // anywhere:\n * toast({\n *   title: \"File deleted\",\n *   action: { label: \"Undo\", onClick: restore, altText: \"Restore it from the Trash\" },\n * });\n */\nfunction Toaster({\n  position = \"bottom-right\",\n  duration = 5000,\n  label = \"Notifications\",\n  closeLabel = \"Close\",\n  toastLabel = \"Notification\",\n  className,\n  ...props\n}: ToasterProps) {\n  const items = useToasts();\n  return (\n    <ToastPrimitive.Provider\n      duration={duration}\n      label={toastLabel}\n      swipeDirection={swipeDirection[position]}\n    >\n      {items.map(({ id, open, title, description, action, variant = \"default\", duration }) => (\n        <ToastPrimitive.Root\n          key={id}\n          data-slot=\"toast\"\n          data-variant={variant}\n          open={open}\n          onOpenChange={(next) => {\n            if (!next) dismiss(id);\n          }}\n          duration={duration}\n          type={variant === \"destructive\" ? \"foreground\" : \"background\"}\n          className={cn(\n            \"group pointer-events-auto relative flex w-full items-start gap-3 overflow-hidden rounded-md p-4 pr-10 shadow-lg\",\n            toastVariant[variant],\n            \"data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:translate-y-[var(--radix-toast-swipe-move-y)] data-[swipe=move]:transition-none\",\n            \"data-[swipe=cancel]:translate-x-0 data-[swipe=cancel]:translate-y-0 data-[swipe=cancel]:transition-transform motion-reduce:transition-none\",\n            \"data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=end]:translate-y-[var(--radix-toast-swipe-end-y)]\",\n            // animate-in/out sit behind motion-safe: so reduced motion really turns them off.\n            \"motion-safe:data-[state=open]:animate-in data-[state=open]:fade-in-0\",\n            \"motion-safe:data-[state=closed]:animate-out data-[state=closed]:fade-out-80\",\n            toastMotion[position]\n          )}\n        >\n          {variant === \"success\" ? (\n            <CircleCheckIcon\n              aria-hidden=\"true\"\n              data-slot=\"toast-icon\"\n              className=\"text-success mt-0.5 size-4 shrink-0\"\n            />\n          ) : variant === \"destructive\" ? (\n            <CircleAlertIcon\n              aria-hidden=\"true\"\n              data-slot=\"toast-icon\"\n              className=\"mt-0.5 size-4 shrink-0\"\n            />\n          ) : null}\n          <div data-slot=\"toast-body\" className=\"grid flex-1 gap-1\">\n            {title ? (\n              <ToastPrimitive.Title data-slot=\"toast-title\" className=\"text-sm font-semibold\">\n                {title}\n              </ToastPrimitive.Title>\n            ) : null}\n            {description ? (\n              <ToastPrimitive.Description\n                data-slot=\"toast-description\"\n                className=\"text-sm opacity-90\"\n              >\n                {description}\n              </ToastPrimitive.Description>\n            ) : null}\n          </div>\n          {action ? (\n            <ToastPrimitive.Action\n              data-slot=\"toast-action\"\n              altText={action.altText}\n              onClick={action.onClick}\n              className={cn(\n                \"inline-flex h-8 shrink-0 cursor-pointer items-center justify-center self-center rounded-md border bg-transparent px-3 text-sm font-medium\",\n                \"hover:bg-accent hover:text-accent-foreground transition-colors motion-reduce:transition-none\",\n                \"focus-visible:ring-ring/50 outline-none focus-visible:ring-[3px]\",\n                \"group-data-[variant=destructive]:border-destructive-foreground/40 group-data-[variant=destructive]:hover:bg-destructive-foreground/10 group-data-[variant=destructive]:hover:text-destructive-foreground\"\n              )}\n            >\n              {action.label}\n            </ToastPrimitive.Action>\n          ) : null}\n          <ToastPrimitive.Close\n            data-slot=\"toast-close\"\n            aria-label={closeLabel}\n            className={cn(\n              \"absolute top-2 right-2 inline-flex size-6 cursor-pointer items-center justify-center rounded-md opacity-70\",\n              \"transition-opacity outline-none hover:opacity-100 motion-reduce:transition-none\",\n              \"focus-visible:ring-ring/50 focus-visible:opacity-100 focus-visible:ring-[3px]\",\n              \"[&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4\"\n            )}\n          >\n            <XIcon aria-hidden=\"true\" />\n          </ToastPrimitive.Close>\n        </ToastPrimitive.Root>\n      ))}\n      <ToastPrimitive.Viewport\n        data-slot=\"toaster\"\n        data-position={position}\n        label={label}\n        className={cn(\n          \"fixed z-[100] flex max-h-screen w-full gap-2 p-4 outline-none sm:max-w-[420px]\",\n          \"focus-visible:ring-ring/50 focus-visible:ring-[3px]\",\n          viewportPosition[position],\n          className\n        )}\n        {...props}\n      />\n    </ToastPrimitive.Provider>\n  );\n}\n\nexport {\n  toast,\n  Toaster,\n  useToasts,\n  type ToastAction,\n  type ToasterPosition,\n  type ToasterProps,\n  type ToastHandle,\n  type ToastItem,\n  type ToastOptions,\n  type ToastVariant,\n};\n",
      "type": "registry:ui"
    }
  ],
  "type": "registry:ui"
}