text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = void 0;
  
  var React = _interopRequireWildcard(require("react"));
  
  var PropTypes = _interopRequireWildcard(require("prop-types"));
  
  var _classnames = _interopRequireDefault(require("classnames"));
  
  var _omit = _interopRequireDefault(require("omit.js"));
  
  var _debounce = _interopRequireDefault(require("lodash/debounce"));
  
  var _configProvider = require("../config-provider");
  
  var _type = require("../_util/type");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
  
  function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  
  var __rest = void 0 && (void 0).__rest || function (s, e) {
    var t = {};
  
    for (var p in s) {
      if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
    }
  
    if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
    }
    return t;
  };
  
  var SpinSizes = (0, _type.tuple)('small', 'default', 'large'); // Render indicator
  
  var defaultIndicator = null;
  
  function renderIndicator(prefixCls, props) {
    var indicator = props.indicator;
    var dotClassName = "".concat(prefixCls, "-dot");
  
    if (React.isValidElement(indicator)) {
      return React.cloneElement(indicator, {
        className: (0, _classnames["default"])(indicator.props.className, dotClassName)
      });
    }
  
    if (React.isValidElement(defaultIndicator)) {
      return React.cloneElement(defaultIndicator, {
        className: (0, _classnames["default"])(defaultIndicator.props.className, dotClassName)
      });
    }
  
    return React.createElement("span", {
      className: (0, _classnames["default"])(dotClassName, "".concat(prefixCls, "-dot-spin"))
    }, React.createElement("i", {
      className: "".concat(prefixCls, "-dot-item")
    }), React.createElement("i", {
      className: "".concat(prefixCls, "-dot-item")
    }), React.createElement("i", {
      className: "".concat(prefixCls, "-dot-item")
    }), React.createElement("i", {
      className: "".concat(prefixCls, "-dot-item")
    }));
  }
  
  function shouldDelay(spinning, delay) {
    return !!spinning && !!delay && !isNaN(Number(delay));
  }
  
  var Spin =
  /*#__PURE__*/
  function (_React$Component) {
    _inherits(Spin, _React$Component);
  
    function Spin(props) {
      var _this;
  
      _classCallCheck(this, Spin);
  
      _this = _possibleConstructorReturn(this, _getPrototypeOf(Spin).call(this, props));
  
      _this.debouncifyUpdateSpinning = function (props) {
        var _ref = props || _this.props,
            delay = _ref.delay;
  
        if (delay) {
          _this.cancelExistingSpin();
  
          _this.updateSpinning = (0, _debounce["default"])(_this.originalUpdateSpinning, delay);
        }
      };
  
      _this.updateSpinning = function () {
        var spinning = _this.props.spinning;
        var currentSpinning = _this.state.spinning;
  
        if (currentSpinning !== spinning) {
          _this.setState({
            spinning: spinning
          });
        }
      };
  
      _this.renderSpin = function (_ref2) {
        var _classNames;
  
        var getPrefixCls = _ref2.getPrefixCls;
  
        var _a = _this.props,
            customizePrefixCls = _a.prefixCls,
            className = _a.className,
            size = _a.size,
            tip = _a.tip,
            wrapperClassName = _a.wrapperClassName,
            style = _a.style,
            restProps = __rest(_a, ["prefixCls", "className", "size", "tip", "wrapperClassName", "style"]);
  
        var spinning = _this.state.spinning;
        var prefixCls = getPrefixCls('spin', customizePrefixCls);
        var spinClassName = (0, _classnames["default"])(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-sm"), size === 'small'), _defineProperty(_classNames, "".concat(prefixCls, "-lg"), size === 'large'), _defineProperty(_classNames, "".concat(prefixCls, "-spinning"), spinning), _defineProperty(_classNames, "".concat(prefixCls, "-show-text"), !!tip), _classNames), className); // fix https://fb.me/react-unknown-prop
  
        var divProps = (0, _omit["default"])(restProps, ['spinning', 'delay', 'indicator']);
        var spinElement = React.createElement("div", _extends({}, divProps, {
          style: style,
          className: spinClassName
        }), renderIndicator(prefixCls, _this.props), tip ? React.createElement("div", {
          className: "".concat(prefixCls, "-text")
        }, tip) : null);
  
        if (_this.isNestedPattern()) {
          var containerClassName = (0, _classnames["default"])("".concat(prefixCls, "-container"), _defineProperty({}, "".concat(prefixCls, "-blur"), spinning));
          return React.createElement("div", _extends({}, divProps, {
            className: (0, _classnames["default"])("".concat(prefixCls, "-nested-loading"), wrapperClassName)
          }), spinning && React.createElement("div", {
            key: "loading"
          }, spinElement), React.createElement("div", {
            className: containerClassName,
            key: "container"
          }, _this.props.children));
        }
  
        return spinElement;
      };
  
      var spinning = props.spinning,
          delay = props.delay;
      var shouldBeDelayed = shouldDelay(spinning, delay);
      _this.state = {
        spinning: spinning && !shouldBeDelayed
      };
      _this.originalUpdateSpinning = _this.updateSpinning;
  
      _this.debouncifyUpdateSpinning(props);
  
      return _this;
    }
  
    _createClass(Spin, [{
      key: "isNestedPattern",
      value: function isNestedPattern() {
        return !!(this.props && this.props.children);
      }
    }, {
      key: "componentWillUnmount",
      value: function componentWillUnmount() {
        this.cancelExistingSpin();
      }
    }, {
      key: "cancelExistingSpin",
      value: function cancelExistingSpin() {
        var updateSpinning = this.updateSpinning;
  
        if (updateSpinning && updateSpinning.cancel) {
          updateSpinning.cancel();
        }
      }
    }, {
      key: "componentDidMount",
      value: function componentDidMount() {
        this.updateSpinning();
      }
    }, {
      key: "componentDidUpdate",
      value: function componentDidUpdate() {
        this.debouncifyUpdateSpinning();
        this.updateSpinning();
      }
    }, {
      key: "render",
      value: function render() {
        return React.createElement(_configProvider.ConfigConsumer, null, this.renderSpin);
      }
    }], [{
      key: "setDefaultIndicator",
      value: function setDefaultIndicator(indicator) {
        defaultIndicator = indicator;
      }
    }]);
  
    return Spin;
  }(React.Component);
  
  Spin.defaultProps = {
    spinning: true,
    size: 'default',
    wrapperClassName: ''
  };
  Spin.propTypes = {
    prefixCls: PropTypes.string,
    className: PropTypes.string,
    spinning: PropTypes.bool,
    size: PropTypes.oneOf(SpinSizes),
    wrapperClassName: PropTypes.string,
    indicator: PropTypes.element
  };
  var _default = Spin;
  exports["default"] = _default;
  //# sourceMappingURL=index.js.map
  