import s, { useState as v, useEffect as p, 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 b } from "react-feather";
import { u as D } from "./useHeaderAlerts-15020c2b.mjs";
const T = "floatingAlert _floatingAlert_b9c31", k = "messageContainer _messageContainer_c65e6", x = "icon _icon_dc9b5", F = "close _close_4a6c4", R = "success _success_2e31b", z = "danger _danger_b5e8b", L = "info _info_a227c", M = "warning _warning_265de", O = "help _help_2cd79", P = "message _message_3095c", a = {
  floatingAlert: T,
  messageContainer: k,
  icon: x,
  close: F,
  success: R,
  danger: z,
  info: L,
  warning: M,
  help: O,
  message: P
};
class f 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" })
    ));
  }
}
f.defaultProps = {};
function U(o) {
  switch (o) {
    case c.success:
      return /* @__PURE__ */ s.createElement(b, 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 } = D(), m = (e) => ({ ...e, id: C() });
  p(() => {
    d(Array.from(r.popAll()).map(m));
  }, []);
  const _ = E(0);
  p(() => {
    _.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(
    f,
    {
      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
};
