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

function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

/**
 * 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);

  var _super = _createSuper(Loading);

  function Loading(props, context) {
    var _this;

    _classCallCheck(this, Loading);

    _this = _super.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 /*#__PURE__*/React.createElement("div", {
        className: classNames(prefixCls, _defineProperty({}, "".concat(prefixCls, "-show"), show), className),
        style: style
      }, /*#__PURE__*/React.createElement(CSSTransition, {
        in: show,
        timeout: this.duration,
        classNames: "".concat(prefixCls, "-mask"),
        appear: true,
        mountOnEnter: true,
        unmountOnExit: true
      }, /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-mask")
      }, /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-backdrop")
      }), /*#__PURE__*/isValidElement(indicator) ? /*#__PURE__*/React.cloneElement(indicator, {
        className: classNames("".concat(prefixCls, "-indicator"), indicator.props.className)
      }) : null, /*#__PURE__*/React.createElement("span", {
        className: "".concat(prefixCls, "-text")
      }, loadingText))), React.Children.map(children, function (child) {
        return /*#__PURE__*/isValidElement(child) ? /*#__PURE__*/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: /*#__PURE__*/React.createElement(Rolling, {
    size: "large"
  }),
  show: false,
  loadingText: '加载中...'
});

export default Loading;