import { __read } from "../../../../../../../tslib@2.6.2/node_modules/tslib/tslib.es6.js";
import { useEffect, useContext } from "react";
import { isAnimationControls } from "../../animation/utils/is-animation-controls.js";
import { usePresence } from "../../components/AnimatePresence/use-presence.js";
import { PresenceContext } from "../../context/PresenceContext.js";
import { createAnimationState } from "../../render/utils/animation-state.js";
import { AnimationType } from "../../render/utils/types.js";
import { makeRenderlessComponent } from "../utils/make-renderless-component.js";
var animations = {
  animation: makeRenderlessComponent(function(_a) {
    var visualElement = _a.visualElement, animate = _a.animate;
    visualElement.animationState || (visualElement.animationState = createAnimationState(visualElement));
    if (isAnimationControls(animate)) {
      useEffect(function() {
        return animate.subscribe(visualElement);
      }, [animate]);
    }
  }),
  exit: makeRenderlessComponent(function(props) {
    var custom = props.custom, visualElement = props.visualElement;
    var _a = __read(usePresence(), 2), isPresent = _a[0], safeToRemove = _a[1];
    var presenceContext = useContext(PresenceContext);
    useEffect(function() {
      var _a2, _b;
      visualElement.isPresent = isPresent;
      var animation = (_a2 = visualElement.animationState) === null || _a2 === void 0 ? void 0 : _a2.setActive(AnimationType.Exit, !isPresent, { custom: (_b = presenceContext === null || presenceContext === void 0 ? void 0 : presenceContext.custom) !== null && _b !== void 0 ? _b : custom });
      !isPresent && (animation === null || animation === void 0 ? void 0 : animation.then(safeToRemove));
    }, [isPresent]);
  })
};
export {
  animations
};
//# sourceMappingURL=animations.js.map
