{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "toast",
  "title": "Toast",
  "author": "AlgorizeTech",
  "description": "Ask the user to pick one of 4 toast variants: https://avaraui.com/view/toast. This item holds 4 of them as looks of one component (default, minimal, glow, glass). Skip the question if the user already named one. A provider-based toast system with six screen positions, action buttons and auto-dismiss. Use it for transient confirmations triggered from anywhere in the tree.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/ToastBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport { AlertCircle, AlertTriangle, BadgeCheck, CheckCircle2, Info, X } from \"lucide-react\";\nimport React, { useCallback, useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport { ToastContext, type ToastProps } from \"./toast-context\";\n\n// ==========================================\n// DYNAMIC THEME ENGINE\n// ==========================================\nexport type ToastVariant = \"default\" | \"glow\" | \"glass\" | \"minimal\";\nexport type ToastPosition = \"top-right\" | \"top-left\" | \"top-center\" | \"bottom-right\" | \"bottom-left\" | \"bottom-center\";\n\n// Stack geometry: how far each card behind the front one peeks out, how much\n// it shrinks, how many stay visible, and the gap between cards once expanded.\nconst STACK_PEEK = 12;\nconst STACK_SCALE = 0.05;\nconst STACK_VISIBLE = 3;\nconst STACK_GAP = 12;\n\n// Entrance: 0.4s back.out(1.5) from 30px off the edge at 90% scale. Exit:\n// 0.3s power2.in back out to the same spot, from wherever the card is.\nconst BACK_OUT =\n  \"linear(0, .1434, .2741, .3925, .4993, .5949, .68, .7551, .8207, .8775, .9259, .9666, 1, 1.0268, 1.0474, 1.0625, 1.0726, 1.0782, 1.08, 1.0784, 1.0741, 1.0675, 1.0593, 1.0499, 1.04, 1.0301, 1.0207, 1.0125, 1.0059, 1.0016, 1)\";\nconst POWER2_IN = \"cubic-bezier(0.3333, 0, 0.6667, 0)\";\nconst ENTER_MS = 400;\nconst EXIT_MS = 300;\n\n// ==========================================\n// INDIVIDUAL TOAST COMPONENT (Web Animations API)\n// ==========================================\ninterface ToastItemProps extends ToastProps {\n  onRemove: (id: string) => void;\n  variant: ToastVariant;\n  position: ToastPosition;\n  /** Freezes the auto-dismiss timer — used by the stack while it is expanded. */\n  paused?: boolean;\n}\n\nconst ToastItem = ({ id, title, description, type = \"default\", duration = 5000, action, onRemove, variant, position, paused = false }: ToastItemProps) => {\n  const toastRef = useRef<HTMLDivElement>(null);\n  const [hovered, setHovered] = useState(false);\n  // Set once the exit starts: the close button, the action and the timer can\n  // all ask for it, and only the first request counts.\n  const closing = useRef(false);\n  const enterRef = useRef<Animation | null>(null);\n  const removeTimer = useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  // Determine entrance direction based on position\n  const isTop = position.includes(\"top\");\n  const yOffset = isTop ? -30 : 30;\n\n  // Handle Exit — starts from the card's current look, so closing during the\n  // entrance carries on from mid-flight instead of jumping to the end first.\n  const handleClose = useCallback(() => {\n    const el = toastRef.current;\n    if (!el || closing.current) return;\n    closing.current = true;\n    const now = getComputedStyle(el);\n    const from = { opacity: now.opacity, transform: now.transform };\n    enterRef.current?.cancel();\n    let removed = false;\n    const remove = () => {\n      if (removed) return;\n      removed = true;\n      if (removeTimer.current) clearTimeout(removeTimer.current);\n      onRemove(id);\n    };\n    el.animate(\n      [from, { opacity: 0, transform: `translateY(${yOffset}px) scale(0.9)` }],\n      { duration: EXIT_MS, easing: POWER2_IN, fill: \"forwards\" },\n    ).finished.then(remove, () => {});\n    // Finish events can lag in a background tab; removal must not.\n    removeTimer.current = setTimeout(remove, EXIT_MS + 50);\n  }, [id, onRemove, yOffset]);\n\n  // Handle Entrance\n  useEffect(() => {\n    const el = toastRef.current;\n    if (!el || closing.current) return;\n    const enter = (enterRef.current = el.animate(\n      [\n        { opacity: 0, transform: `translateY(${yOffset}px) scale(0.9)` },\n        { opacity: 1, transform: \"translateY(0px) scale(1)\" },\n      ],\n      { duration: ENTER_MS, easing: BACK_OUT },\n    ));\n    return () => {\n      if (!closing.current) enter.cancel();\n    };\n  }, [yOffset]);\n\n  useEffect(\n    () => () => {\n      if (removeTimer.current) clearTimeout(removeTimer.current);\n    },\n    [],\n  );\n\n  // Auto-dismiss with a pausable timer: hovering the card (or the expanded\n  // stack) stops the clock and resumes from where it left off.\n  const remaining = useRef(duration);\n  const startedAt = useRef(0);\n  const timer = useRef<ReturnType<typeof setTimeout> | null>(null);\n  const isPaused = paused || hovered;\n\n  useEffect(() => {\n    if (duration <= 0 || isPaused) return;\n    startedAt.current = Date.now();\n    timer.current = setTimeout(handleClose, remaining.current);\n    return () => {\n      if (!timer.current) return;\n      clearTimeout(timer.current);\n      timer.current = null;\n      remaining.current = Math.max(0, remaining.current - (Date.now() - startedAt.current));\n    };\n  }, [duration, isPaused, handleClose]);\n\n  // Styling logic & type specific colors\n  const typeStyles = {\n    success: {\n      icon: variant === \"glass\" ? BadgeCheck : CheckCircle2,\n      iconColor: \"text-emerald-500\",\n      colorVar: \"#10b981\", // emerald-500\n      glowBorder: \"border-emerald-500/40 dark:border-emerald-500/50\",\n      glowShadow: \"shadow-[0_0_20px_rgba(16,185,129,0.35)]\",\n      minimalBorder: \"border-l-emerald-500\",\n    },\n    error: {\n      icon: AlertCircle,\n      iconColor: \"text-red-500\",\n      colorVar: \"#ef4444\", // red-500\n      glowBorder: \"border-red-500/40 dark:border-red-500/50\",\n      glowShadow: \"shadow-[0_0_20px_rgba(239,68,68,0.35)]\",\n      minimalBorder: \"border-l-red-500\",\n    },\n    warning: {\n      icon: AlertTriangle,\n      iconColor: \"text-amber-500\",\n      colorVar: \"#f59e0b\", // amber-500\n      glowBorder: \"border-amber-500/40 dark:border-amber-500/50\",\n      glowShadow: \"shadow-[0_0_20px_rgba(245,158,11,0.35)]\",\n      minimalBorder: \"border-l-amber-500\",\n    },\n    info: {\n      icon: Info,\n      iconColor: \"text-blue-500\",\n      colorVar: \"#3b82f6\", // blue-500\n      glowBorder: \"border-blue-500/40 dark:border-blue-500/50\",\n      glowShadow: \"shadow-[0_0_20px_rgba(59,130,246,0.35)]\",\n      minimalBorder: \"border-l-blue-500\",\n    },\n    default: {\n      icon: null,\n      iconColor: \"\",\n      colorVar: \"var(--primary)\",\n      glowBorder: \"border-primary/40 dark:border-primary/50\",\n      glowShadow: \"shadow-[0_0_20px_var(--primary)]\",\n      minimalBorder: \"border-l-primary\",\n    },\n  };\n  const currentType = typeStyles[type];\n  const { icon: Icon, iconColor } = currentType;\n\n  const variantStyles = {\n    default: \"bg-background border border-border shadow-xl\",\n    glow: cn(\n      \"bg-background shadow-lg border text-foreground\",\n      currentType.glowBorder,\n      currentType.glowShadow\n    ),\n    glass: \"rounded-2xl border border-foreground/10 bg-card/70 backdrop-blur-xl shadow-2xl shadow-black/10 dark:shadow-black/40\",\n    minimal: cn(\"border-l-4 rounded-l-none bg-background shadow-md\", currentType.minimalBorder),\n  };\n\n  const isGlass = variant === \"glass\";\n  const glassStyle: React.CSSProperties = isGlass\n    ? { backgroundImage: `radial-gradient(140% 120% at 0% 0%, color-mix(in oklab, ${currentType.colorVar} 35%, transparent) 0%, transparent 65%)` }\n    : {};\n\n  return (\n    <div\n      ref={toastRef}\n      className={cn(\"pointer-events-auto flex w-full max-w-sm items-start gap-4 rounded-xl p-4 transition-colors\", variantStyles[variant])}\n      style={glassStyle}\n      onMouseEnter={() => setHovered(true)}\n      onMouseLeave={() => setHovered(false)}\n    >\n      {Icon && (\n        <Icon\n          className={cn(\n            \"mt-0.5 w-5 h-5 shrink-0\",\n            iconColor,\n            // Glass icons are solid badges: fill with the accent, cut the glyph out in the card colour.\n            isGlass && \"w-6 h-6 fill-current stroke-card\",\n          )}\n        />\n      )}\n\n      <div className=\"flex flex-col gap-1 w-full min-w-0\">\n        <h3 className=\"text-sm font-semibold text-foreground\">{title}</h3>\n        {description && <p className=\"text-sm text-muted-foreground\">{description}</p>}\n\n        {action && (\n          <button onClick={() => { action.onClick(); handleClose(); }} className=\"mt-2 w-max px-3 py-1.5 rounded-lg text-xs font-semibold bg-primary text-primary-foreground transition-all hover:opacity-90 active:scale-95 shadow-xs\">\n            {action.label}\n          </button>\n        )}\n      </div>\n\n      <button onClick={handleClose} className={cn(\"shrink-0 p-1 rounded-md opacity-50 hover:opacity-100 hover:bg-muted transition-all\", isGlass && \"self-center\")}>\n        <X className=\"w-4 h-4\" />\n      </button>\n    </div>\n  );\n};\n\n// ==========================================\n// STACK SLOT (measures its toast so the expanded stack can lay cards out)\n// ==========================================\ninterface StackSlotProps {\n  id: string;\n  onHeight: (id: string, height: number) => void;\n  className?: string;\n  style?: React.CSSProperties;\n  children: React.ReactNode;\n}\n\nconst StackSlot = ({ id, onHeight, className, style, children }: StackSlotProps) => {\n  const ref = useRef<HTMLDivElement>(null);\n\n  useLayoutEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const report = () => onHeight(id, el.offsetHeight);\n    report();\n    const observer = new ResizeObserver(report);\n    observer.observe(el);\n    return () => observer.disconnect();\n  }, [id, onHeight]);\n\n  return (\n    <div ref={ref} className={className} style={style}>\n      {children}\n    </div>\n  );\n};\n\n// ==========================================\n// TOAST PROVIDER (WRAPPER)\n// ==========================================\nexport interface ToastProviderProps {\n  children: React.ReactNode;\n  variant?: ToastVariant;\n  position?: ToastPosition;\n  /**\n   * Piles toasts on top of each other — the newest in front, older ones\n   * peeking out behind it. Hovering the pile fans it out into a list.\n   */\n  stack?: boolean;\n}\n\nexport function ToastProvider({ children, variant = \"default\", position = \"bottom-right\", stack = false }: ToastProviderProps) {\n  const [toasts, setToasts] = useState<ToastProps[]>([]);\n  const [hovered, setHovered] = useState(false);\n  const [heights, setHeights] = useState<Record<string, number>>({});\n\n  const toast = useCallback((props: Omit<ToastProps, \"id\">) => {\n    const id = Math.random().toString(36).substring(2, 9);\n    setToasts((prev) => [...prev, { id, ...props }]);\n  }, []);\n\n  const dismiss = useCallback((id: string) => {\n    setToasts((prev) => prev.filter((t) => t.id !== id));\n    setHeights((prev) => {\n      if (!(id in prev)) return prev;\n      const next = { ...prev };\n      delete next[id];\n      return next;\n    });\n  }, []);\n\n  const reportHeight = useCallback((id: string, height: number) => {\n    setHeights((prev) => (prev[id] === height ? prev : { ...prev, [id]: height }));\n  }, []);\n\n  const isTop = position.startsWith(\"top\");\n  const expanded = stack && hovered;\n\n  // The stack is one absolutely-laid-out column, so it only needs a corner.\n  const stackPositionClasses = {\n    \"top-right\": \"top-4 right-4\",\n    \"top-left\": \"top-4 left-4\",\n    \"top-center\": \"top-4 left-1/2 -translate-x-1/2\",\n    \"bottom-right\": \"bottom-4 right-4\",\n    \"bottom-left\": \"bottom-4 left-4\",\n    \"bottom-center\": \"bottom-4 left-1/2 -translate-x-1/2\",\n  };\n\n  // No overflow clipping here: variants like `glow` paint outside the card\n  // via box-shadow, and a clipped container would crop the halo on every edge.\n  const positionClasses = {\n    \"top-right\": \"top-0 right-0 sm:top-4 sm:right-4 flex-col\",\n    \"top-left\": \"top-0 left-0 sm:top-4 sm:left-4 flex-col\",\n    \"top-center\": \"top-0 left-1/2 -translate-x-1/2 sm:top-4 flex-col\",\n    \"bottom-right\": \"bottom-0 right-0 sm:bottom-4 sm:right-4 flex-col-reverse\",\n    \"bottom-left\": \"bottom-0 left-0 sm:bottom-4 sm:left-4 flex-col-reverse\",\n    \"bottom-center\": \"bottom-0 left-1/2 -translate-x-1/2 sm:bottom-4 flex-col-reverse\",\n  };\n\n  // Stack layout: index 0 is the front (newest) card. Collapsed cards sit\n  // behind the front one, each nudged out and scaled down a little; expanded\n  // cards are laid out by their measured heights so nothing overlaps.\n  const ordered = stack ? [...toasts].reverse() : toasts;\n  const offsets: number[] = [];\n  let running = 0;\n  ordered.forEach((t, i) => {\n    offsets[i] = expanded ? running : i * STACK_PEEK;\n    running += (heights[t.id] ?? 0) + STACK_GAP;\n  });\n  const stackHeight = Math.max(running - STACK_GAP, 0) + STACK_PEEK * (STACK_VISIBLE - 1);\n\n  return (\n    <ToastContext.Provider value={{ toast, dismiss }}>\n      {children}\n      {stack ? (\n        <div\n          className={cn(\n            \"fixed z-[100] w-[calc(100%-2rem)] sm:w-96\",\n            expanded ? \"pointer-events-auto\" : \"pointer-events-none\",\n            stackPositionClasses[position],\n          )}\n          style={{ height: stackHeight }}\n          onMouseEnter={() => setHovered(true)}\n          onMouseLeave={() => setHovered(false)}\n        >\n          {ordered.map((t, i) => {\n            const hidden = !expanded && i >= STACK_VISIBLE;\n            const scale = expanded ? 1 : 1 - i * STACK_SCALE;\n            const translate = isTop ? offsets[i] : -offsets[i];\n            return (\n              <StackSlot\n                key={t.id}\n                id={t.id}\n                onHeight={reportHeight}\n                className={cn(\n                  \"absolute inset-x-0 transition-all duration-300 ease-out\",\n                  isTop ? \"top-0\" : \"bottom-0\",\n                  hidden && \"opacity-0 pointer-events-none\",\n                )}\n                style={{\n                  zIndex: 100 - i,\n                  transform: `translateY(${translate}px) scale(${scale})`,\n                  transformOrigin: isTop ? \"top center\" : \"bottom center\",\n                }}\n              >\n                <ToastItem {...t} onRemove={dismiss} variant={variant} position={position} paused={expanded} />\n              </StackSlot>\n            );\n          })}\n        </div>\n      ) : (\n        <div className={cn(\"fixed z-[100] flex max-h-screen w-full sm:w-auto p-4 sm:p-0 gap-3 pointer-events-none\", positionClasses[position])}>\n          {toasts.map((t) => (\n            <ToastItem key={t.id} {...t} onRemove={dismiss} variant={variant} position={position} />\n          ))}\n        </div>\n      )}\n    </ToastContext.Provider>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/ToastBlock.tsx"
    },
    {
      "path": "src/components/custom/blocks/toast-context.ts",
      "content": "\"use client\";\n\nimport { createContext, useContext } from \"react\";\n\nexport type ToastType = \"success\" | \"error\" | \"info\" | \"warning\" | \"default\";\n\nexport interface ToastProps {\n  id: string;\n  title: string;\n  description?: string;\n  type?: ToastType;\n  duration?: number;\n  action?: { label: string; onClick: () => void };\n}\n\ninterface ToastContextType {\n  toast: (props: Omit<ToastProps, \"id\">) => void;\n  dismiss: (id: string) => void;\n}\n\nexport const ToastContext = createContext<ToastContextType | undefined>(undefined);\n\nexport const useToast = () => {\n  const context = useContext(ToastContext);\n  if (!context) throw new Error(\"useToast must be used within a ToastProvider\");\n  return context;\n};\n",
      "type": "registry:component",
      "target": "components/custom/blocks/toast-context.ts"
    }
  ],
  "docs": "Named exports: ToastProvider (ToastBlock.tsx) and useToast (toast-context.ts, which installs alongside). Wrap your app in ToastProvider, then call `toast()` from useToast. Types: success | error | info | warning | default; `variant` is default | glow | glass | minimal. Set `stack` on the provider to pile toasts behind the newest one (hover fans them out). Set `duration` to 0 to require manual dismissal; hovering pauses the timer. `sonner` does the same job with a module-level API and no provider.",
  "categories": [
    "feedback"
  ],
  "type": "registry:component"
}
