import o from "react";
import l from "shortid";
import { headerAlertsQueue as r } from "./accelbyte-widgets155.mjs";
import "./accelbyte-widgets237.mjs";
import { FloatingAlert as m } from "./accelbyte-widgets238.mjs";
const s = class extends o.Component {
  constructor(t) {
    super(t), this.popAlertFromQueue = () => {
      const e = r.pop();
      e && this.addAlerts([s.convertAlertToAlertWithId(e)]);
    }, this.state = {
      alerts: /* @__PURE__ */ new Set()
    };
  }
  static convertAlertToAlertWithId(t) {
    return { ...t, id: l() };
  }
  componentDidMount() {
    this.addAlerts(Array.from(r.popAll()).map(s.convertAlertToAlertWithId)), r.event.register("push", this.popAlertFromQueue);
  }
  componentWillUnmount() {
    r.event.unregister("push", this.popAlertFromQueue);
  }
  renderAlerts() {
    return Array.from(this.state.alerts).map((t) => /* @__PURE__ */ o.createElement(
      m,
      {
        key: t.id,
        type: t.type,
        onDismiss: () => {
          this.state.alerts.delete(t), this.setState({}), t.dismiss && t.dismiss();
        }
      },
      t.element
    )).slice(-1);
  }
  render() {
    const { className: t = "commonAlertsContainer" } = this.props;
    return /* @__PURE__ */ o.createElement("div", { className: t }, this.renderAlerts());
  }
  addAlerts(t) {
    const e = this.state.alerts;
    for (const i of t)
      e.add(i), i.autoDismiss && setTimeout(() => {
        this.removeAlert(i);
      }, s.timeOut);
    this.setState({ alerts: e });
  }
  removeAlert(t) {
    const e = this.state.alerts;
    e.delete(t), this.setState({ alerts: e });
  }
};
let n = s;
n.timeOut = 4e3;
export {
  n as Alerts
};
