import { __rest as I } from "../../../../../tslib/tslib.es6.es.js";
import { useContext as k } from "react";
import { isAnimationControls as P } from "../../animation/utils/is-animation-controls.es.js";
import { PresenceContext as F } from "../../context/PresenceContext.es.js";
import { checkIfControllingVariants as b, checkIfVariantNode as x, resolveVariantFromProps as N } from "../../render/utils/variants.es.js";
import { useConstant as R } from "../../utils/use-constant.es.js";
import { resolveMotionValue as B } from "../../value/utils/resolve-motion-value.es.js";
import { MotionContext as L } from "../../context/MotionContext/index.es.js";
function C(r, t, a, o) {
  var n = r.scrapeMotionValuesFromProps, c = r.createRenderState, f = r.onMount, e = {
    latestValues: U(t, a, o, n),
    renderState: c()
  };
  return f && (e.mount = function(i) {
    return f(t, i, e);
  }), e;
}
var K = function(r) {
  return function(t, a) {
    var o = k(L), n = k(F);
    return a ? C(r, t, o, n) : R(function() {
      return C(r, t, o, n);
    });
  };
};
function U(r, t, a, o) {
  var n = {}, c = (a == null ? void 0 : a.initial) === !1, f = o(r);
  for (var e in f)
    n[e] = B(f[e]);
  var i = r.initial, m = r.animate, M = b(r), S = x(r);
  t && S && !M && r.inherit !== !1 && (i != null || (i = t.initial), m != null || (m = t.animate));
  var d = c || i === !1, l = d ? m : i;
  if (l && typeof l != "boolean" && !P(l)) {
    var h = Array.isArray(l) ? l : [l];
    h.forEach(function(y) {
      var v = N(r, y);
      if (!!v) {
        var V = v.transitionEnd;
        v.transition;
        var A = I(v, ["transitionEnd", "transition"]);
        for (var u in A) {
          var s = A[u];
          if (Array.isArray(s)) {
            var E = d ? s.length - 1 : 0;
            s = s[E];
          }
          s !== null && (n[u] = s);
        }
        for (var u in V)
          n[u] = V[u];
      }
    });
  }
  return n;
}
export {
  K as makeUseVisualState
};
//# sourceMappingURL=use-visual-state.es.js.map
