import { __assign as p, __rest as h, __spreadArray as U, __read as F } from "../../../../../tslib/tslib.es6.es.js";
import { secondsToMilliseconds as d } from "../../utils/time-conversion.es.js";
import { isEasingArray as V, easingDefinitionToFunction as c } from "./easing.es.js";
import { isAnimatable as v } from "./is-animatable.es.js";
import { getDefaultTransition as x } from "./default-transitions.es.js";
import { warning as b } from "../../../../../hey-listen/dist/hey-listen.es.es.js";
import { getAnimatableNone as D } from "../../render/dom/value-types/animatable-none.es.js";
import { instantAnimationState as I } from "../../utils/use-instant-transition-state.es.js";
import { resolveFinalValueInKeyframes as K } from "../../utils/resolve-value.es.js";
import { inertia as P } from "../../../../../popmotion/dist/es/animations/inertia.es.js";
import { animate as R } from "../../../../../popmotion/dist/es/animations/index.es.js";
function Z(e) {
  e.when, e.delay, e.delayChildren, e.staggerChildren, e.staggerDirection, e.repeat, e.repeatType, e.repeatDelay, e.from;
  var t = h(e, ["when", "delay", "delayChildren", "staggerChildren", "staggerDirection", "repeat", "repeatType", "repeatDelay", "from"]);
  return !!Object.keys(t).length;
}
var g = !1;
function _(e) {
  var t = e.ease, n = e.times, i = e.yoyo, l = e.flip, f = e.loop, r = h(e, ["ease", "times", "yoyo", "flip", "loop"]), o = p({}, r);
  return n && (o.offset = n), r.duration && (o.duration = d(r.duration)), r.repeatDelay && (o.repeatDelay = d(r.repeatDelay)), t && (o.ease = V(t) ? t.map(c) : c(t)), r.type === "tween" && (o.type = "keyframes"), (i || f || l) && (b(!g, "yoyo, loop and flip have been removed from the API. Replace with repeat and repeatType options."), g = !0, i ? o.repeatType = "reverse" : f ? o.repeatType = "loop" : l && (o.repeatType = "mirror"), o.repeat = f || i || l || r.repeat), r.type !== "spring" && (o.type = "keyframes"), o;
}
function j(e, t) {
  var n, i, l = C(e, t) || {};
  return (i = (n = l.delay) !== null && n !== void 0 ? n : e.delay) !== null && i !== void 0 ? i : 0;
}
function E(e) {
  return Array.isArray(e.to) && e.to[0] === null && (e.to = U([], F(e.to), !1), e.to[0] = e.from), e;
}
function M(e, t, n) {
  var i;
  return Array.isArray(t.to) && ((i = e.duration) !== null && i !== void 0 || (e.duration = 0.8)), E(t), Z(e) || (e = p(p({}, e), x(n, t.to))), p(p({}, t), _(e));
}
function N(e, t, n, i, l) {
  var f, r = C(i, e), o = (f = r.from) !== null && f !== void 0 ? f : t.get(), s = v(e, n);
  o === "none" && s && typeof n == "string" ? o = D(e, n) : T(o) && typeof n == "string" ? o = A(n) : !Array.isArray(n) && T(n) && typeof o == "string" && (n = A(o));
  var y = v(e, o);
  b(y === s, "You are trying to animate ".concat(e, ' from "').concat(o, '" to "').concat(n, '". ').concat(o, " is not an animatable value - to enable this animation set ").concat(o, " to a value animatable to ").concat(n, " via the `style` property."));
  function w() {
    var m = {
      from: o,
      to: n,
      velocity: t.getVelocity(),
      onComplete: l,
      onUpdate: function(a) {
        return t.set(a);
      }
    };
    return r.type === "inertia" || r.type === "decay" ? P(p(p({}, m), r)) : R(p(p({}, M(r, m, e)), { onUpdate: function(a) {
      var u;
      m.onUpdate(a), (u = r.onUpdate) === null || u === void 0 || u.call(r, a);
    }, onComplete: function() {
      var a;
      m.onComplete(), (a = r.onComplete) === null || a === void 0 || a.call(r);
    } }));
  }
  function O() {
    var m, a, u = K(n);
    return t.set(u), l(), (m = r == null ? void 0 : r.onUpdate) === null || m === void 0 || m.call(r, u), (a = r == null ? void 0 : r.onComplete) === null || a === void 0 || a.call(r), { stop: function() {
    } };
  }
  return !y || !s || r.type === !1 ? O : w;
}
function T(e) {
  return e === 0 || typeof e == "string" && parseFloat(e) === 0 && e.indexOf(" ") === -1;
}
function A(e) {
  return typeof e == "number" ? 0 : D("", e);
}
function C(e, t) {
  return e[t] || e.default || e;
}
function X(e, t, n, i) {
  return i === void 0 && (i = {}), I.current && (i = { type: !1 }), t.start(function(l) {
    var f, r, o = N(e, t, n, i, l), s = j(i, e), y = function() {
      return r = o();
    };
    return s ? f = window.setTimeout(y, d(s)) : y(), function() {
      clearTimeout(f), r == null || r.stop();
    };
  });
}
export {
  _ as convertTransitionToAnimationOptions,
  j as getDelayFromTransition,
  M as getPopmotionAnimationOptions,
  C as getValueTransition,
  A as getZeroUnit,
  E as hydrateKeyframes,
  Z as isTransitionDefined,
  T as isZero,
  X as startAnimation
};
//# sourceMappingURL=transitions.es.js.map
