"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const tslib_es6 = require("../../../../../../../tslib@2.6.2/node_modules/tslib/tslib.es6.js");
const React = require("react");
const isAnimationControls = require("../../animation/utils/is-animation-controls.js");
const usePresence = require("../../components/AnimatePresence/use-presence.js");
const PresenceContext = require("../../context/PresenceContext.js");
const animationState = require("../../render/utils/animation-state.js");
const types = require("../../render/utils/types.js");
const makeRenderlessComponent = require("../utils/make-renderless-component.js");
var animations = {
  animation: makeRenderlessComponent.makeRenderlessComponent(function(_a) {
    var visualElement = _a.visualElement, animate = _a.animate;
    visualElement.animationState || (visualElement.animationState = animationState.createAnimationState(visualElement));
    if (isAnimationControls.isAnimationControls(animate)) {
      React.useEffect(function() {
        return animate.subscribe(visualElement);
      }, [animate]);
    }
  }),
  exit: makeRenderlessComponent.makeRenderlessComponent(function(props) {
    var custom = props.custom, visualElement = props.visualElement;
    var _a = tslib_es6.__read(usePresence.usePresence(), 2), isPresent = _a[0], safeToRemove = _a[1];
    var presenceContext = React.useContext(PresenceContext.PresenceContext);
    React.useEffect(function() {
      var _a2, _b;
      visualElement.isPresent = isPresent;
      var animation = (_a2 = visualElement.animationState) === null || _a2 === void 0 ? void 0 : _a2.setActive(types.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]);
  })
};
exports.animations = animations;
//# sourceMappingURL=animations.js.map
