import O from "../../@babel/runtime/helpers/esm/defineProperty.mjs";
import t from "../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import q from "../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import z from "../../@babel/runtime/helpers/esm/typeof.mjs";
import B from "../../classnames/index.mjs";
import F from "../../rc-util/es/Dom/findDOMNode.mjs";
import { fillRef as G, supportRef as I } from "../../rc-util/es/ref.mjs";
import * as o from "react";
import { useRef as g } from "react";
import { Context as J } from "./context.mjs";
import K from "./DomWrapper.mjs";
import Q from "./hooks/useStatus.mjs";
import { isActive as X } from "./hooks/useStepQueue.mjs";
import { STATUS_NONE as Y, STEP_PREPARE as Z, STEP_START as ee } from "./interface.mjs";
import { supportTransition as re, getTransitionName as h } from "./util/motion.mjs";
function te(v) {
  var T = v;
  z(v) === "object" && (T = v.transitionSupport);
  function L(r, m) {
    return !!(r.motionName && T && m !== !1);
  }
  var y = /* @__PURE__ */ o.forwardRef(function(r, m) {
    var C = r.visible, E = C === void 0 ? !0 : C, _ = r.removeOnLeave, b = _ === void 0 ? !0 : _, D = r.forceRender, i = r.children, f = r.motionName, c = r.leavedClassName, $ = r.eventProps, j = o.useContext(J), w = j.motion, V = L(r, w), p = g(), M = g();
    function k() {
      try {
        return p.current instanceof HTMLElement ? p.current : F(M.current);
      } catch {
        return null;
      }
    }
    var x = Q(V, E, k, r), l = q(x, 4), d = l[0], S = l[1], H = l[2], R = l[3], P = o.useRef(R);
    R && (P.current = !0);
    var n = o.useCallback(function(N) {
      p.current = N, G(m, N);
    }, [m]), e, s = t(t({}, $), {}, {
      visible: E
    });
    if (!i)
      e = null;
    else if (d === Y)
      R ? e = i(t({}, s), n) : !b && P.current && c ? e = i(t(t({}, s), {}, {
        className: c
      }), n) : D || !b && !c ? e = i(t(t({}, s), {}, {
        style: {
          display: "none"
        }
      }), n) : e = null;
    else {
      var u, a;
      S === Z ? a = "prepare" : X(S) ? a = "active" : S === ee && (a = "start");
      var A = h(f, "".concat(d, "-").concat(a));
      e = i(t(t({}, s), {}, {
        className: B(h(f, d), (u = {}, O(u, A, A && a), O(u, f, typeof f == "string"), u)),
        style: H
      }), n);
    }
    if (/* @__PURE__ */ o.isValidElement(e) && I(e)) {
      var U = e, W = U.ref;
      W || (e = /* @__PURE__ */ o.cloneElement(e, {
        ref: n
      }));
    }
    return /* @__PURE__ */ o.createElement(K, {
      ref: M
    }, e);
  });
  return y.displayName = "CSSMotion", y;
}
const Re = te(re);
export {
  Re as default,
  te as genCSSMotion
};
