import { useContext as C } from "react";
import { MotionContext as x } from "../../context/MotionContext/index.es.js";
import { PresenceContext as S } from "../../context/PresenceContext.es.js";
import { useConstant as h } from "../../utils/use-constant.es.js";
import { resolveMotionValue as M } from "../../../../../../../motion-dom@12.38.0/node_modules/motion-dom/dist/es/value/utils/resolve-motion-value.es.js";
import { isControllingVariants as N, isVariantNode as P } from "../../../../../../../motion-dom@12.38.0/node_modules/motion-dom/dist/es/render/utils/is-controlling-variants.es.js";
import { isAnimationControls as T } from "../../../../../../../motion-dom@12.38.0/node_modules/motion-dom/dist/es/render/utils/is-animation-controls.es.js";
import { resolveVariantFromProps as $ } from "../../../../../../../motion-dom@12.38.0/node_modules/motion-dom/dist/es/render/utils/resolve-variants.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] = M(o[l]);
  let { initial: m, animate: u } = t;
  const g = N(t), v = P(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" && !T(a)) {
    const l = Array.isArray(a) ? a : [a];
    for (let d = 0; d < l.length; d++) {
      const V = $(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(x), n = C(S), o = () => b(t, i, s, n);
  return e ? o() : h(o);
};
export {
  z as makeUseVisualState
};
//# sourceMappingURL=use-visual-state.es.js.map
