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 o } from "./Alert-1277e378.mjs";
import N from "classnames";
import { X as H, AlertCircle as b, CheckCircle as S } from "react-feather";
import { u as D } from "./useHeaderAlerts-206faff0.mjs";
const T = "floatingAlert _floatingAlert_3a543", k = "messageContainer _messageContainer_83924", x = "icon _icon_7d622", F = "close _close_a6d40", R = "success _success_b562f", z = "danger _danger_4b05b", L = "info _info_a6040", M = "warning _warning_b536f", O = "help _help_37b38", P = "message _message_eb92c", a = {
  floatingAlert: T,
  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(c) {
  switch (c) {
    case o.success:
      return /* @__PURE__ */ s.createElement(S, null);
    case o.danger:
      return /* @__PURE__ */ s.createElement(I, null);
    case o.warning:
      return /* @__PURE__ */ s.createElement(b, null);
    case o.info:
      return /* @__PURE__ */ s.createElement(y, null);
    case o.help:
      return /* @__PURE__ */ s.createElement(w, null);
    default:
      return null;
  }
}
const W = 4e3, K = (c) => {
  const [t, l] = v(/* @__PURE__ */ new Set()), { state: n, mutations: r } = D(), 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" } = c;
  return /* @__PURE__ */ s.createElement("div", { className: h }, A());
};
export {
  K as H
};
