import { resolveVariant as l } from "../../render/utils/resolve-dynamic-variants.es.js";
import { calcChildStagger as g } from "../utils/calc-child-stagger.es.js";
import { animateTarget as C } from "./visual-element-target.es.js";
function y(r, i, t = {}) {
  var n;
  const e = l(r, i, t.type === "exit" ? (n = r.presenceContext) == null ? void 0 : n.custom : void 0);
  let { transition: o = r.getDefaultTransition() || {} } = e || {};
  t.transitionOverride && (o = t.transitionOverride);
  const a = e ? () => Promise.all(C(r, e, t)) : () => Promise.resolve(), s = r.variantChildren && r.variantChildren.size ? (f = 0) => {
    const { delayChildren: d = 0, staggerChildren: m, staggerDirection: h } = o;
    return P(r, i, f, d, m, h, t);
  } : () => Promise.resolve(), { when: c } = o;
  if (c) {
    const [f, d] = c === "beforeChildren" ? [a, s] : [s, a];
    return f().then(() => d());
  } else
    return Promise.all([a(), s(t.delay)]);
}
function P(r, i, t = 0, e = 0, o = 0, a = 1, s) {
  const c = [];
  for (const n of r.variantChildren)
    n.notify("AnimationStart", i), c.push(y(n, i, {
      ...s,
      delay: t + (typeof e == "function" ? 0 : e) + g(r.variantChildren, n, e, o, a)
    }).then(() => n.notify("AnimationComplete", i)));
  return Promise.all(c);
}
export {
  y as animateVariant
};
//# sourceMappingURL=visual-element-variant.es.js.map
