import K from "../../@babel/runtime/helpers/esm/extends.mjs";
import _ from "../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import f from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import x from "../../@babel/runtime/helpers/esm/classCallCheck.mjs";
import O from "../../@babel/runtime/helpers/esm/createClass.mjs";
import g from "../../@babel/runtime/helpers/esm/assertThisInitialized.mjs";
import R from "../../@babel/runtime/helpers/esm/inherits.mjs";
import D from "../../@babel/runtime/helpers/esm/createSuper.mjs";
import y from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import * as c from "react";
import V from "./CSSMotion.mjs";
import { STATUS_REMOVED as E, parseKeys as N, diffKeys as U, STATUS_REMOVE as j, STATUS_ADD as F, STATUS_KEEP as I } from "./util/diff.mjs";
import { supportTransition as $ } from "./util/motion.mjs";
var w = ["component", "children", "onVisibleChanged", "onAllRemoved"], z = ["status"], W = ["eventProps", "visible", "children", "motionName", "motionAppear", "motionEnter", "motionLeave", "motionLeaveImmediately", "motionDeadline", "removeOnLeave", "leavedClassName", "onAppearPrepare", "onAppearStart", "onAppearActive", "onAppearEnd", "onEnterStart", "onEnterActive", "onEnterEnd", "onLeaveStart", "onLeaveActive", "onLeaveEnd"];
function q(B) {
  var P = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : V, h = /* @__PURE__ */ function(T) {
    R(p, T);
    var k = D(p);
    function p() {
      var n;
      x(this, p);
      for (var i = arguments.length, a = new Array(i), e = 0; e < i; e++)
        a[e] = arguments[e];
      return n = k.call.apply(k, [this].concat(a)), y(g(n), "state", {
        keyEntities: []
      }), y(g(n), "removeKey", function(s) {
        var u = n.state.keyEntities, o = u.map(function(t) {
          return t.key !== s ? t : f(f({}, t), {}, {
            status: E
          });
        });
        return n.setState({
          keyEntities: o
        }), o.filter(function(t) {
          var r = t.status;
          return r !== E;
        }).length;
      }), n;
    }
    return O(p, [{
      key: "render",
      value: function() {
        var i = this, a = this.state.keyEntities, e = this.props, s = e.component, u = e.children, o = e.onVisibleChanged, t = e.onAllRemoved, r = _(e, w), S = s || c.Fragment, v = {};
        return W.forEach(function(m) {
          v[m] = r[m], delete r[m];
        }), delete r.keys, /* @__PURE__ */ c.createElement(S, r, a.map(function(m, b) {
          var A = m.status, l = _(m, z), L = A === F || A === I;
          return /* @__PURE__ */ c.createElement(P, K({}, v, {
            key: l.key,
            visible: L,
            eventProps: l,
            onVisibleChanged: function(d) {
              if (o == null || o(d, {
                key: l.key
              }), !d) {
                var M = i.removeKey(l.key);
                M === 0 && t && t();
              }
            }
          }), function(C, d) {
            return u(f(f({}, C), {}, {
              index: b
            }), d);
          });
        }));
      }
    }], [{
      key: "getDerivedStateFromProps",
      value: function(i, a) {
        var e = i.keys, s = a.keyEntities, u = N(e), o = U(s, u);
        return {
          keyEntities: o.filter(function(t) {
            var r = s.find(function(S) {
              var v = S.key;
              return t.key === v;
            });
            return !(r && r.status === E && t.status === j);
          })
        };
      }
    }]), p;
  }(c.Component);
  return y(h, "defaultProps", {
    component: "div"
  }), h;
}
const ie = q($);
export {
  ie as default,
  q as genCSSMotionList
};
