import J from "../../@babel/runtime/helpers/esm/extends.mjs";
import ge from "../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import I from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import he from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import O from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import j from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import P, { useContext as pe, useRef as ke, useState as Q, useEffect as U } from "react";
import D from "../../classnames/index.mjs";
import "../../rc-motion/es/CSSMotion.mjs";
import Se from "../../rc-motion/es/CSSMotionList.mjs";
import Ce from "./Notice.mjs";
import { NotificationContext as xe } from "./NotificationProvider.mjs";
import Le from "./hooks/useStack.mjs";
var _e = ["className", "style", "classNames", "styles"], Ee = function(o) {
  var d, X = o.configList, r = o.placement, f = o.prefixCls, Y = o.className, Z = o.style, C = o.motion, K = o.onAllNoticeRemoved, R = o.onNoticeClose, $ = o.stack, ee = pe(xe), u = ee.classNames, i = ke({}), te = Q(null), T = j(te, 2), n = T[0], oe = T[1], ne = Q([]), V = j(ne, 2), y = V[0], x = V[1], t = X.map(function(e) {
    return {
      config: e,
      key: String(e.key)
    };
  }), ae = Le($), q = j(ae, 2), s = q[0], L = q[1], z = L.offset, ie = L.threshold, se = L.gap, N = s && (y.length > 0 || t.length <= ie), re = typeof C == "function" ? C(r) : C;
  return U(function() {
    s && y.length > 1 && x(function(e) {
      return e.filter(function(l) {
        return t.some(function(g) {
          var _ = g.key;
          return l === _;
        });
      });
    });
  }, [y, t, s]), U(function() {
    var e;
    if (s && i.current[(e = t[t.length - 1]) === null || e === void 0 ? void 0 : e.key]) {
      var l;
      oe(i.current[(l = t[t.length - 1]) === null || l === void 0 ? void 0 : l.key]);
    }
  }, [t, s]), /* @__PURE__ */ P.createElement(Se, J({
    key: r,
    className: D(f, "".concat(f, "-").concat(r), u == null ? void 0 : u.list, Y, (d = {}, O(d, "".concat(f, "-stack"), !!s), O(d, "".concat(f, "-stack-expanded"), N), d)),
    style: Z,
    keys: t,
    motionAppear: !0
  }, re, {
    onAllRemoved: function() {
      K(r);
    }
  }), function(e, l) {
    var g = e.config, _ = e.className, le = e.style, ce = e.index, B = g, E = B.key, fe = B.times, a = String(E), m = g, ue = m.className, me = m.style, h = m.classNames, p = m.styles, ve = he(m, _e), A = t.findIndex(function(S) {
      return S.key === a;
    }), k = {};
    if (s) {
      var v = t.length - 1 - (A > -1 ? A : ce - 1), F = r === "top" || r === "bottom" ? "-50%" : "0";
      if (v > 0) {
        var M, W, b;
        k.height = N ? (M = i.current[a]) === null || M === void 0 ? void 0 : M.offsetHeight : n == null ? void 0 : n.offsetHeight;
        for (var G = 0, H = 0; H < v; H++) {
          var w;
          G += ((w = i.current[t[t.length - 1 - H].key]) === null || w === void 0 ? void 0 : w.offsetHeight) + se;
        }
        var de = (N ? G : v * z) * (r.startsWith("top") ? 1 : -1), ye = !N && n !== null && n !== void 0 && n.offsetWidth && (W = i.current[a]) !== null && W !== void 0 && W.offsetWidth ? ((n == null ? void 0 : n.offsetWidth) - z * 2 * (v < 3 ? v : 3)) / ((b = i.current[a]) === null || b === void 0 ? void 0 : b.offsetWidth) : 1;
        k.transform = "translate3d(".concat(F, ", ").concat(de, "px, 0) scaleX(").concat(ye, ")");
      } else
        k.transform = "translate3d(".concat(F, ", 0, 0)");
    }
    return /* @__PURE__ */ P.createElement("div", {
      ref: l,
      className: D("".concat(f, "-notice-wrapper"), _, h == null ? void 0 : h.wrapper),
      style: I(I(I({}, le), k), p == null ? void 0 : p.wrapper),
      onMouseEnter: function() {
        return x(function(c) {
          return c.includes(a) ? c : [].concat(ge(c), [a]);
        });
      },
      onMouseLeave: function() {
        return x(function(c) {
          return c.filter(function(Ne) {
            return Ne !== a;
          });
        });
      }
    }, /* @__PURE__ */ P.createElement(Ce, J({}, ve, {
      ref: function(c) {
        A > -1 ? i.current[a] = c : delete i.current[a];
      },
      prefixCls: f,
      classNames: h,
      styles: p,
      className: D(ue, u == null ? void 0 : u.notice),
      style: me,
      times: fe,
      key: E,
      eventKey: E,
      onNoticeClose: R,
      hovering: s && y.length > 0
    })));
  });
};
process.env.NODE_ENV !== "production" && (Ee.displayName = "NoticeList");
export {
  Ee as default
};
