"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _reactTransitionGroup = require("react-transition-group");
var _makeAnimations = _interopRequireDefault(require("./makeAnimations"));
var _excluded = ["in", "as", "toggle", "speed", "timing", "transformOrigin", "mount", "children"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
var Animation = function Animation(_ref) {
  var isVisible = _ref["in"],
    as = _ref.as,
    toggle = _ref.toggle,
    _ref$speed = _ref.speed,
    speed = _ref$speed === void 0 ? 200 : _ref$speed,
    _ref$timing = _ref.timing,
    timing = _ref$timing === void 0 ? "" : _ref$timing,
    transformOrigin = _ref.transformOrigin,
    mount = _ref.mount,
    children = _ref.children,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var animations = (0, _react.useMemo)(function () {
    return (0, _makeAnimations["default"])({
      toggle: toggle,
      timing: timing,
      speed: speed,
      transformOrigin: transformOrigin
    });
  }, []);
  var StyledContainer = (0, _react.useMemo)(function () {
    return as && (0, _styledComponents["default"])(as).withConfig({
      displayName: "animation",
      componentId: "sc-6srjcx-0"
    })(["", ""], function (props) {
      return props.transitionStyling;
    });
  }, []);
  var ref = (0, _react.useRef)();
  return /*#__PURE__*/_react["default"].createElement(_reactTransitionGroup.Transition, {
    nodeRef: ref,
    "in": isVisible,
    timeout: speed,
    mountOnEnter: !mount,
    unmountOnExit: !mount
  }, function (transition) {
    var transitionStyling = animations[transition];
    if (StyledContainer) {
      return /*#__PURE__*/_react["default"].createElement(StyledContainer, _extends({
        transitionStyling: transitionStyling
      }, rest, {
        ref: ref
      }), children({
        transition: transition,
        transitionStyling: transitionStyling
      }));
    }
    return children({
      transition: transition,
      transitionStyling: transitionStyling,
      ref: ref
    });
  });
};
var _default = exports["default"] = Animation;