"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Transition = Transition;

var _react = _interopRequireDefault(require("react"));

var _reactTransitionGroup = require("react-transition-group");

var _util = require("../../../util");

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

/* eslint-disable import/prefer-default-export */

/**
 *
 * @param {object} config
 * @param {function} config.enter - fired before the "entering"
 * @param {function} config.exit - fired before the "exiting"
 * @param {number} [config.timeout=200]
 * @param {boolean} extraWrap
 */
function Transition(config) {
  var extraWrap = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
  return function (ComposedComponent) {
    function Wrapped(props) {
      var onEnter = function onEnter(node) {
        if (config.enter) {
          config.enter(node, _util.func.noop);
        }
      };

      var onExit = function onExit(node) {
        if (config.exit) {
          config.exit(node, _util.func.noop);
        }
      };

      var timeout = config.timeout === undefined ? 200 : config.timeout;
      var child = extraWrap ? _react["default"].createElement("div", null, _react["default"].createElement(ComposedComponent, props)) : _react["default"].createElement(ComposedComponent, props);
      return _react["default"].createElement(_reactTransitionGroup.Transition, {
        timeout: timeout,
        "in": props["in"],
        mountOnEnter: true,
        unmountOnExit: true,
        onEnter: onEnter,
        onExit: onExit
      }, child);
    }

    Wrapped.displayName = "Transition.".concat(ComposedComponent.displayName || 'anonymous');
    return Wrapped;
  };
}