"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const isAnimationControls = require("./dist-es-animation-utils-is-animation-controls.cjs");
const animationState = require("./dist-es-render-utils-animation-state.cjs");
const Feature = require("./dist-es-motion-features-Feature.cjs");
class AnimationFeature extends Feature.Feature {
  /**
   * We dynamically generate the AnimationState manager as it contains a reference
   * to the underlying animation library. We only want to load that if we load this,
   * so people can optionally code split it out using the `m` component.
   */
  constructor(node) {
    super(node);
    node.animationState || (node.animationState = animationState.createAnimationState(node));
  }
  updateAnimationControlsSubscription() {
    const { animate } = this.node.getProps();
    if (isAnimationControls.isAnimationControls(animate)) {
      this.unmountControls = animate.subscribe(this.node);
    }
  }
  /**
   * Subscribe any provided AnimationControls to the component's VisualElement
   */
  mount() {
    this.updateAnimationControlsSubscription();
  }
  update() {
    const { animate } = this.node.getProps();
    const { animate: prevAnimate } = this.node.prevProps || {};
    if (animate !== prevAnimate) {
      this.updateAnimationControlsSubscription();
    }
  }
  unmount() {
    var _a;
    this.node.animationState.reset();
    (_a = this.unmountControls) === null || _a === void 0 ? void 0 : _a.call(this);
  }
}
exports.AnimationFeature = AnimationFeature;
//# sourceMappingURL=dist-es-motion-features-animation-index.cjs.map
