import Te from "../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import i from "../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import d from "../../../@babel/runtime/helpers/esm/slicedToArray.mjs";
import x from "../../../rc-util/es/hooks/useState.mjs";
import * as X from "react";
import { useRef as N, useEffect as Q } from "react";
import { STATUS_NONE as c, STEP_PREPARE as f, STEP_ACTIVE as A, STEP_PREPARED as Pe, STATUS_APPEAR as T, STATUS_ENTER as P, STATUS_LEAVE as L, STEP_START as R } from "../interface.mjs";
import Le from "./useDomMotionEvents.mjs";
import Re from "./useIsomorphicLayoutEffect.mjs";
import ye, { SkipStep as ge, DoStep as De, isActive as Me } from "./useStepQueue.mjs";
function He(H, s, Y, e) {
  var j = e.motionEnter, y = j === void 0 ? !0 : j, k = e.motionAppear, g = k === void 0 ? !0 : k, w = e.motionLeave, p = w === void 0 ? !0 : w, O = e.motionDeadline, Z = e.motionLeaveImmediately, b = e.onAppearPrepare, ee = e.onEnterPrepare, te = e.onLeavePrepare, ne = e.onAppearStart, re = e.onEnterStart, oe = e.onLeaveStart, ae = e.onAppearActive, ie = e.onEnterActive, ue = e.onLeaveActive, D = e.onAppearEnd, M = e.onEnterEnd, _ = e.onLeaveEnd, h = e.onVisibleChanged, se = x(), $ = d(se, 2), u = $[0], ve = $[1], fe = x(c), q = d(fe, 2), o = q[0], E = q[1], ce = x(null), z = d(ce, 2), le = z[0], B = z[1], V = N(!1), I = N(null);
  function S() {
    return Y();
  }
  var F = N(!1);
  function G() {
    E(c, !0), B(null, !0);
  }
  function J(r) {
    var t = S();
    if (!(r && !r.deadline && r.target !== t)) {
      var n = F.current, a;
      o === T && n ? a = D == null ? void 0 : D(t, r) : o === P && n ? a = M == null ? void 0 : M(t, r) : o === L && n && (a = _ == null ? void 0 : _(t, r)), o !== c && n && a !== !1 && G();
    }
  }
  var me = Le(J), de = d(me, 1), pe = de[0], K = function(t) {
    var n, a, m;
    switch (t) {
      case T:
        return n = {}, i(n, f, b), i(n, R, ne), i(n, A, ae), n;
      case P:
        return a = {}, i(a, f, ee), i(a, R, re), i(a, A, ie), a;
      case L:
        return m = {}, i(m, f, te), i(m, R, oe), i(m, A, ue), m;
      default:
        return {};
    }
  }, l = X.useMemo(function() {
    return K(o);
  }, [o]), Ee = ye(o, !H, function(r) {
    if (r === f) {
      var t = l[f];
      return t ? t(S()) : ge;
    }
    if (v in l) {
      var n;
      B(((n = l[v]) === null || n === void 0 ? void 0 : n.call(l, S(), null)) || null);
    }
    return v === A && (pe(S()), O > 0 && (clearTimeout(I.current), I.current = setTimeout(function() {
      J({
        deadline: !0
      });
    }, O))), v === Pe && G(), De;
  }), W = d(Ee, 2), Se = W[0], v = W[1], Ae = Me(v);
  F.current = Ae, Re(function() {
    ve(s);
    var r = V.current;
    V.current = !0;
    var t;
    !r && s && g && (t = T), r && s && y && (t = P), (r && !s && p || !r && Z && !s && p) && (t = L);
    var n = K(t);
    t && (H || n[f]) ? (E(t), Se()) : E(c);
  }, [s]), Q(function() {
    // Cancel appear
    (o === T && !g || // Cancel enter
    o === P && !y || // Cancel leave
    o === L && !p) && E(c);
  }, [g, y, p]), Q(function() {
    return function() {
      V.current = !1, clearTimeout(I.current);
    };
  }, []);
  var C = X.useRef(!1);
  Q(function() {
    u && (C.current = !0), u !== void 0 && o === c && ((C.current || u) && (h == null || h(u)), C.current = !0);
  }, [u, o]);
  var U = le;
  return l[f] && v === R && (U = Te({
    transition: "none"
  }, U)), [o, v, U, u ?? s];
}
export {
  He as default
};
