/* eslint-disable import/prefer-default-export */
import React from 'react';
import { Transition as TransitionItem } from 'react-transition-group';
import { func } from '../../../util';
/**
 *
 * @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
 */

export 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, func.noop);
        }
      };

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

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

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