import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

/**
 * Spin.jsx
 *
 * @Author: apple
 * @Date: 2018/1/22 22:48
 */
import React, { isValidElement } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { CSSTransition } from 'react-transition-group';
import Rolling from '../icons/internals/Rolling';
/** Loading */

var Loading =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(Loading, _React$PureComponent);

  function Loading(props, context) {
    var _this;

    _classCallCheck(this, Loading);

    _this = _possibleConstructorReturn(this, _getPrototypeOf(Loading).call(this, props, context));
    _this.duration = 300;
    return _this;
  }

  _createClass(Loading, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          prefixCls = _this$props.prefixCls,
          children = _this$props.children,
          loadingText = _this$props.loadingText,
          show = _this$props.show,
          className = _this$props.className,
          style = _this$props.style,
          indicator = _this$props.indicator;
      return React.createElement("div", {
        className: classNames(prefixCls, _defineProperty({}, "".concat(prefixCls, "-show"), show), className),
        style: style
      }, React.createElement(CSSTransition, {
        in: show,
        timeout: this.duration,
        classNames: "".concat(prefixCls, "-mask"),
        appear: true,
        mountOnEnter: true,
        unmountOnExit: true
      }, React.createElement("div", {
        className: "".concat(prefixCls, "-mask")
      }, React.createElement("div", {
        className: "".concat(prefixCls, "-backdrop")
      }), isValidElement(indicator) ? React.cloneElement(indicator, {
        className: classNames("".concat(prefixCls, "-indicator"), indicator.props.className)
      }) : null, React.createElement("span", {
        className: "".concat(prefixCls, "-text")
      }, loadingText))), React.Children.map(children, function (child) {
        return isValidElement(child) ? React.cloneElement(child, {
          className: classNames("".concat(prefixCls, "-container"), child.props.className)
        }) : null;
      }));
    }
  }]);

  return Loading;
}(React.PureComponent);

_defineProperty(Loading, "propTypes", {
  /** loading的图标，可自定义 */
  indicator: PropTypes.node,

  /** 控制显示的图标字体大小 */
  prefixCls: PropTypes.string,

  /** 控制显示 */
  show: PropTypes.bool,

  /** 控制显示的文字 */
  loadingText: PropTypes.string
  /** loading样式类型 */

});

_defineProperty(Loading, "defaultProps", {
  prefixCls: 'ne-loading',
  indicator: React.createElement(Rolling, {
    size: "large"
  }),
  show: false,
  loadingText: '加载中...'
});

export default Loading;