import { useContext as C } from "react";
import { isAnimationControls as x } from "../../animation/utils/is-animation-controls.es.js";
import { MotionContext as S } from "../../context/MotionContext/index.es.js";
import { PresenceContext as h } from "../../context/PresenceContext.es.js";
import { isControllingVariants as M, isVariantNode as N } from "../../render/utils/is-controlling-variants.es.js";
import { resolveVariantFromProps as P } from "../../render/utils/resolve-variants.es.js";
import { useConstant as T } from "../../utils/use-constant.es.js";
import { resolveMotionValue as $ } from "../../value/utils/resolve-motion-value.es.js";
function b({ scrapeMotionValuesFromProps: t, createRenderState: i }, e, s, n) {
  return {
    latestValues: p(e, s, n, t),
    renderState: i()
  };
}
function p(t, i, e, s) {
  const n = {}, o = s(t, {});
  for (const l in o)
    n[l] = $(o[l]);
  let { initial: m, animate: u } = t;
  const g = M(t), v = N(t);
  i && v && !g && t.inherit !== !1 && (m === void 0 && (m = i.initial), u === void 0 && (u = i.animate));
  let c = e ? e.initial === !1 : !1;
  c = c || m === !1;
  const a = c ? u : m;
  if (a && typeof a != "boolean" && !x(a)) {
    const l = Array.isArray(a) ? a : [a];
    for (let d = 0; d < l.length; d++) {
      const V = P(t, l[d]);
      if (V) {
        const { transitionEnd: k, transition: B, ...y } = V;
        for (const f in y) {
          let r = y[f];
          if (Array.isArray(r)) {
            const A = c ? r.length - 1 : 0;
            r = r[A];
          }
          r !== null && (n[f] = r);
        }
        for (const f in k)
          n[f] = k[f];
      }
    }
  }
  return n;
}
const z = (t) => (i, e) => {
  const s = C(S), n = C(h), o = () => b(t, i, s, n);
  return e ? o() : T(o);
};
export {
  z as makeUseVisualState
};
//# sourceMappingURL=use-visual-state.es.js.map
