/**
 * Outside-of-component toast manager. Matches Base UI React's
 * `createToastManager` surface (`add` / `close` / `update` / `promise` +
 * the private " subscribe" channel the provider consumes).
 *
 * The provider subscribes to every emitted event and dispatches to the
 * store. Consumers call this manager's methods anywhere — it does not
 * depend on the Solid owner tree.
 */

let counter = 0;
function gid() {
  counter += 1;
  return `toast-ext-${counter}-${Math.random().toString(36).slice(2, 8)}`;
}

/**
 * Create a standalone toast manager. Pass the returned object to
 * `<Toast.Provider toastManager={...}>` so its events flow into the
 * provider's store.
 */
export function createToastManager() {
  const listeners = new Set();
  function emit(event) {
    for (const listener of listeners) listener(event);
  }
  return {
    " subscribe": listener => {
      listeners.add(listener);
      return () => {
        listeners.delete(listener);
      };
    },
    add(options) {
      const id = options.id ?? gid();
      emit({
        action: "add",
        options: {
          ...options,
          id,
          transitionStatus: "starting"
        }
      });
      return id;
    },
    close(id) {
      emit({
        action: "close",
        options: {
          id
        }
      });
    },
    update(id, updates) {
      emit({
        action: "update",
        options: {
          ...updates,
          id
        }
      });
    },
    promise(promiseValue, options) {
      let handled = promiseValue;
      emit({
        action: "promise",
        options: {
          ...options,
          promise: promiseValue,
          setPromise(p) {
            handled = p;
          }
        }
      });
      return handled;
    }
  };
}
//# sourceMappingURL=create-toast-manager.jsx.map
