import { jsx as l } from "react/jsx-runtime";
import { useRef as p, useState as w, useCallback as h, useEffect as m } from "react";
import { Toast as T } from "../toast/index.js";
import '../../assets/index25.css';const v = "_toasts_19qwq_1", S = {
  toasts: v
}, g = ({
  defaultDurationMs: c = 5e3,
  onRemove: f,
  toasts: i
}) => {
  const r = p(/* @__PURE__ */ new Map()), [n, d] = w(/* @__PURE__ */ new Set()), a = h((e) => {
    d((s) => s.has(e) ? s : new Set(s).add(e));
  }, []);
  return m(() => {
    const e = r.current, s = new Set(i.map((t) => t.id));
    d((t) => {
      const o = new Set([...t].filter((u) => s.has(u)));
      return o.size === t.size ? t : o;
    });
    for (const t of i) {
      if (n.has(t.id) || e.has(t.id)) continue;
      const o = t.durationMs ?? c;
      e.set(t.id, window.setTimeout(() => {
        a(t.id);
      }, o));
    }
    for (const [t, o] of e)
      s.has(t) && !n.has(t) || (window.clearTimeout(o), e.delete(t));
  }, [n, c, a, i]), m(() => {
    const e = r.current;
    return () => {
      for (const s of e.values()) window.clearTimeout(s);
      e.clear();
    };
  }, []), i.length ? /* @__PURE__ */ l("div", { className: S.toasts, "data-component": "toasts", children: i.map((e) => /* @__PURE__ */ l(T, { label: e.label, onClick: () => a(e.id), onExitComplete: () => f(e.id), open: !n.has(e.id), type: e.type }, e.id)) }) : null;
};
export {
  g as Toasts
};
//# sourceMappingURL=index.js.map
