{"version":3,"file":"toast-manager.cjs","sources":["../../../components/toast/toast-manager.ts"],"sourcesContent":["'use client';\n\nimport { Toast as ToastPrimitive } from '@base-ui/react';\nimport { type ReactNode, useMemo } from 'react';\n\nexport interface ToastData {\n  /**\n   * Icon rendered before the toast title. Inherits color from the toast type\n   * (e.g. green for `type: \"success\"`).\n   *\n   * - Omit (or pass `undefined`) to use the default icon for the toast type.\n   * - Pass any React node to override the icon.\n   * - Pass `null` to render no icon at all (opt out of type defaults).\n   */\n  leadingIcon?: ReactNode;\n}\n\ntype BaseManager = ReturnType<\n  typeof ToastPrimitive.createToastManager<ToastData>\n>;\n\n/** Public option shape: hides Base UI's internal storage slot and exposes `leadingIcon` directly. */\ntype WithModifiedOptions<T> = Omit<T, 'data'> & ToastData;\n\nexport type ToastAddOptions = WithModifiedOptions<\n  Parameters<BaseManager['add']>[0]\n>;\n\nexport type ToastUpdateOptions = WithModifiedOptions<\n  Parameters<BaseManager['update']>[1]\n>;\n\nexport interface ToastPromiseOptions<Value> {\n  loading: string | ToastUpdateOptions;\n  success:\n    | string\n    | ToastUpdateOptions\n    | ((result: Value) => string | ToastUpdateOptions);\n  error:\n    | string\n    | ToastUpdateOptions\n    | ((error: unknown) => string | ToastUpdateOptions);\n}\n\nfunction lift<O extends { leadingIcon?: ReactNode }>(options: O) {\n  const { leadingIcon, ...rest } = options;\n  if (leadingIcon === undefined) return rest;\n  return { ...rest, data: { leadingIcon } };\n}\n\nfunction liftDescriptor(option: string | ToastUpdateOptions) {\n  return typeof option === 'string' ? option : lift(option);\n}\n\nfunction liftCallable<Arg>(\n  option:\n    | string\n    | ToastUpdateOptions\n    | ((arg: Arg) => string | ToastUpdateOptions)\n) {\n  if (typeof option === 'function') {\n    return (arg: Arg) => liftDescriptor(option(arg));\n  }\n  return liftDescriptor(option);\n}\n\nfunction liftPromiseOptions<Value>({\n  loading,\n  success,\n  error\n}: ToastPromiseOptions<Value>) {\n  return {\n    loading: liftDescriptor(loading),\n    success: liftCallable(success),\n    error: liftCallable(error)\n  };\n}\n\n/**\n * Public toast manager. Mirrors the Base UI manager but exposes `leadingIcon`\n * as a first-class option on `add`/`update`/`promise`. All other Base UI\n * manager members are preserved.\n */\nexport interface ToastManager\n  extends Omit<BaseManager, 'add' | 'update' | 'promise'> {\n  add: (options: ToastAddOptions) => string;\n  update: (id: string, options: ToastUpdateOptions) => void;\n  promise: <Value>(\n    promise: Promise<Value>,\n    options: ToastPromiseOptions<Value>\n  ) => Promise<Value>;\n}\n\nexport function createToastManager(): ToastManager {\n  const base = ToastPrimitive.createToastManager<ToastData>();\n  return {\n    ...base,\n    add: options => base.add(lift(options)),\n    update: (id, options) => base.update(id, lift(options)),\n    promise: (promise, options) =>\n      base.promise(promise, liftPromiseOptions(options))\n  };\n}\n\nexport const toastManager = createToastManager();\n\ntype BaseHookReturn = ReturnType<\n  typeof ToastPrimitive.useToastManager<ToastData>\n>;\n\n/**\n * Reactive view of the active toast list plus the same `leadingIcon`-aware\n * `add`/`update`/`promise` API as the standalone manager. Must be used inside\n * `<Toast.Provider>`.\n */\nexport interface UseToastManagerReturn\n  extends Omit<BaseHookReturn, 'add' | 'update' | 'promise'> {\n  add: ToastManager['add'];\n  update: ToastManager['update'];\n  promise: ToastManager['promise'];\n}\n\nexport function useToastManager(): UseToastManagerReturn {\n  const base = ToastPrimitive.useToastManager<ToastData>();\n  return useMemo(\n    () => ({\n      ...base,\n      add: options => base.add(lift(options)),\n      update: (id, options) => base.update(id, lift(options)),\n      promise: (promise, options) =>\n        base.promise(promise, liftPromiseOptions(options))\n    }),\n    [base]\n  );\n}\n"],"names":[],"mappings":";;;;;;AA4CA;;;AAEiC;;AAEjC;AAEA;AACE;AACF;AAEA;AAME;AACE;;AAEF;AACF;AAEA;;AAMI;AACA;AACA;;AAEJ;;AAkBE;;AAEE;AACA;AACA;AACA;;AAGJ;AAEa;;AAmBX;AACA;AAEI;AACA;AACA;AACA;AAED;AAGL;;;;"}