function createToastStore() {
  let queue = [];
  const listeners = /* @__PURE__ */ new Set();
  const timers = /* @__PURE__ */ new Map();
  const fire = () => listeners.forEach((l) => l());
  function scheduleRemoval(t) {
    const handle = setTimeout(() => {
      queue = queue.filter((q) => q !== t);
      timers.delete(t);
      fire();
    }, t.ttl);
    timers.set(t, handle);
  }
  function push(t) {
    if (t.group === "save") {
      const last = queue[queue.length - 1];
      if (last && last.group === "save") {
        const m = /^Saved · (\d+) fields$/.exec(last.message);
        const next = m ? Number(m[1]) + 1 : 2;
        const merged = {
          ...last,
          message: `Saved \xB7 ${next} fields`,
          action: last.action ?? t.action
        };
        const prevTimer = timers.get(last);
        if (prevTimer !== void 0) {
          clearTimeout(prevTimer);
          timers.delete(last);
        }
        queue[queue.length - 1] = merged;
        scheduleRemoval(merged);
        fire();
        return;
      }
    }
    queue.push(t);
    scheduleRemoval(t);
    fire();
  }
  function dismiss() {
    const head = queue[0];
    if (!head) return;
    const handle = timers.get(head);
    if (handle !== void 0) {
      clearTimeout(handle);
      timers.delete(head);
    }
    queue = queue.slice(1);
    fire();
  }
  function setCurrentAction(action) {
    if (queue.length === 0) return;
    queue[0] = { ...queue[0], action };
    fire();
  }
  return {
    push,
    current: () => queue[0] ?? null,
    queue: () => [...queue],
    subscribe: (fn) => {
      listeners.add(fn);
      return () => {
        listeners.delete(fn);
      };
    },
    dismiss,
    setCurrentAction
  };
}
export {
  createToastStore
};
//# sourceMappingURL=toast-store.js.map