import g from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import v from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import G from "../../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import * as o from "react";
import Q from "../Notifications.mjs";
var T = ["getContainer", "motion", "prefixCls", "maxCount", "className", "style", "onAllRemoved", "stack", "renderNotifications"], q = function() {
  return document.body;
}, y = 0;
function H() {
  for (var e = {}, i = arguments.length, s = new Array(i), r = 0; r < i; r++)
    s[r] = arguments[r];
  return s.forEach(function(c) {
    c && Object.keys(c).forEach(function(f) {
      var l = c[f];
      l !== void 0 && (e[f] = l);
    });
  }), e;
}
function W() {
  var e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, i = e.getContainer, s = i === void 0 ? q : i, r = e.motion, c = e.prefixCls, f = e.maxCount, l = e.className, x = e.style, R = e.onAllRemoved, N = e.stack, h = e.renderNotifications, k = G(e, T), A = o.useState(), p = v(A, 2), E = p[0], S = p[1], u = o.useRef(), _ = /* @__PURE__ */ o.createElement(Q, {
    container: E,
    ref: u,
    prefixCls: c,
    motion: r,
    maxCount: f,
    className: l,
    style: x,
    onAllRemoved: R,
    stack: N,
    renderNotifications: h
  }), $ = o.useState([]), C = v($, 2), m = C[0], d = C[1], b = o.useMemo(function() {
    return {
      open: function(n) {
        var a = H(k, n);
        (a.key === null || a.key === void 0) && (a.key = "rc-notification-".concat(y), y += 1), d(function(w) {
          return [].concat(g(w), [{
            type: "open",
            config: a
          }]);
        });
      },
      close: function(n) {
        d(function(a) {
          return [].concat(g(a), [{
            type: "close",
            key: n
          }]);
        });
      },
      destroy: function() {
        d(function(n) {
          return [].concat(g(n), [{
            type: "destroy"
          }]);
        });
      }
    };
  }, []);
  return o.useEffect(function() {
    S(s());
  }), o.useEffect(function() {
    u.current && m.length && (m.forEach(function(t) {
      switch (t.type) {
        case "open":
          u.current.open(t.config);
          break;
        case "close":
          u.current.close(t.key);
          break;
        case "destroy":
          u.current.destroy();
          break;
      }
    }), d(function(t) {
      return t.filter(function(n) {
        return !m.includes(n);
      });
    }));
  }, [m]), [b, _];
}
export {
  W as default
};
