import s, { useState as v, useEffect as f, useRef as E } from "react";
import C from "shortid";
import { H as w, I as y, D as I } from "./InfoIcon-c86fd057.mjs";
import { A as c } from "./Alert-1277e378.mjs";
import N from "classnames";
import { X as H, AlertCircle as S, CheckCircle as D } from "react-feather";
import { u as T } from "./useHeaderAlerts-15020c2b.mjs";
const b = "floatingAlert _floatingAlert_110aa", k = "messageContainer _messageContainer_9cd2c", x = "icon _icon_3a8d9", F = "close _close_2f39c", R = "success _success_4d5be", z = "danger _danger_21bfb", L = "info _info_cdf42", M = "warning _warning_a5e3a", O = "help _help_0ff55", P = "message _message_ad2c9", a = {
  floatingAlert: b,
  messageContainer: k,
  icon: x,
  close: F,
  success: R,
  danger: z,
  info: L,
  warning: M,
  help: O,
  message: P
};
class p extends s.Component {
  constructor(t) {
    super(t);
  }
  render() {
    const { className: t, children: l, type: n, onDismiss: r } = this.props;
    return /* @__PURE__ */ s.createElement("div", { className: N(a.floatingAlert, t, n && a[n]), role: "alert" }, /* @__PURE__ */ s.createElement("div", { className: a.messageContainer }, /* @__PURE__ */ s.createElement("span", { className: a.icon }, U(n)), /* @__PURE__ */ s.createElement("span", { className: a.message }, l)), !!r && /* @__PURE__ */ s.createElement(
      "span",
      {
        className: a.close,
        onClick: () => {
          r && r();
        }
      },
      /* @__PURE__ */ s.createElement(H, { size: "1em" })
    ));
  }
}
p.defaultProps = {};
function U(o) {
  switch (o) {
    case c.success:
      return /* @__PURE__ */ s.createElement(D, null);
    case c.danger:
      return /* @__PURE__ */ s.createElement(I, null);
    case c.warning:
      return /* @__PURE__ */ s.createElement(S, null);
    case c.info:
      return /* @__PURE__ */ s.createElement(y, null);
    case c.help:
      return /* @__PURE__ */ s.createElement(w, null);
    default:
      return null;
  }
}
const W = 4e3, K = (o) => {
  const [t, l] = v(/* @__PURE__ */ new Set()), { state: n, mutations: r } = T(), m = (e) => ({ ...e, id: C() });
  f(() => {
    d(Array.from(r.popAll()).map(m));
  }, []);
  const _ = E(0);
  f(() => {
    _.current >= n.alerts.length || (g(), _.current = n.alerts.length);
  }, [n.alerts.length]);
  const d = (e) => {
    for (const i of e)
      t.add(i), i.autoDismiss && setTimeout(() => {
        u(i);
      }, W);
    l(new Set(t));
  }, u = (e) => {
    t.delete(e), l(new Set(t));
  }, g = () => {
    const e = r.pop();
    e && d([m(e)]);
  }, A = () => Array.from(t).map((e) => /* @__PURE__ */ s.createElement(
    p,
    {
      key: e.id,
      type: e.type,
      onDismiss: () => {
        t.delete(e), l(/* @__PURE__ */ new Set()), e.dismiss && e.dismiss();
      }
    },
    e.element
  )).slice(-1), { className: h = "commonAlertsContainer" } = o;
  return /* @__PURE__ */ s.createElement("div", { className: h }, A());
};
export {
  K as H
};
