import _extends from"babel-runtime/helpers/extends";import _defineProperty from"babel-runtime/helpers/defineProperty";import _classCallCheck from"babel-runtime/helpers/classCallCheck";import _createClass from"babel-runtime/helpers/createClass";import _possibleConstructorReturn from"babel-runtime/helpers/possibleConstructorReturn";import _inherits from"babel-runtime/helpers/inherits";var __rest=this&&this.__rest||function(e,t){var i={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(i[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(s=Object.getOwnPropertySymbols(e);n<s.length;n++)t.indexOf(s[n])<0&&(i[s[n]]=e[s[n]])}return i};import*as React from"react";import*as PropTypes from"prop-types";import classNames from"classnames";import Animate from"rc-animate";import isCssAnimationSupported from"../_util/isCssAnimationSupported";import omit from"omit.js";var Spin=function(e){function t(e){_classCallCheck(this,t);var i=_possibleConstructorReturn(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e)),s=e.spinning;return i.state={spinning:s},i}return _inherits(t,e),_createClass(t,[{key:"isNestedPattern",value:function(){return!(!this.props||!this.props.children)}},{key:"componentDidMount",value:function(){isCssAnimationSupported()||this.setState({notCssAnimationSupported:!0})}},{key:"componentWillUnmount",value:function(){this.debounceTimeout&&clearTimeout(this.debounceTimeout),this.delayTimeout&&clearTimeout(this.delayTimeout)}},{key:"componentWillReceiveProps",value:function(e){var t=this,i=this.props.spinning,s=e.spinning,n=this.props.delay;this.debounceTimeout&&clearTimeout(this.debounceTimeout),i&&!s?(this.debounceTimeout=window.setTimeout(function(){return t.setState({spinning:s})},200),this.delayTimeout&&clearTimeout(this.delayTimeout)):s&&n&&!isNaN(Number(n))?(this.delayTimeout&&clearTimeout(this.delayTimeout),this.delayTimeout=window.setTimeout(function(){return t.setState({spinning:s})},n)):this.setState({spinning:s})}},{key:"renderIndicator",value:function(){var e=this.props,t=e.prefixCls,i=e.indicator,s=t+"-dot";return React.isValidElement(i)?React.cloneElement(i,{className:classNames(i.props.className,s)}):React.createElement("span",{className:classNames(s,t+"-dot-spin")},React.createElement("i",null),React.createElement("i",null),React.createElement("i",null))}},{key:"render",value:function(){var e,t=this.props,i=t.className,s=t.size,n=t.prefixCls,r=t.tip,a=t.wrapperClassName,o=__rest(t,["className","size","prefixCls","tip","wrapperClassName"]),l=this.state,p=l.spinning,m=l.notCssAnimationSupported,c=classNames(n,(_defineProperty(e={},n+"-sm","small"===s),_defineProperty(e,n+"-lg","large"===s),_defineProperty(e,n+"-spinning",p),_defineProperty(e,n+"-show-text",!!r||m),e),i),u=omit(o,["spinning","delay","indicator"]),d=React.createElement("div",_extends({},u,{className:c}),this.renderIndicator(),r?React.createElement("div",{className:n+"-text"},r):null);if(this.isNestedPattern()){var f,h=n+"-nested-loading";a&&(h+=" "+a);var y=classNames((_defineProperty(f={},n+"-container",!0),_defineProperty(f,n+"-blur",p),f));return React.createElement(Animate,_extends({},u,{component:"div",className:h,style:null,transitionName:"fade"}),p&&React.createElement("div",{key:"loading"},d),React.createElement("div",{className:y,key:"container"},this.props.children))}return d}}]),t}(React.Component);export default Spin;Spin.defaultProps={prefixCls:"dt-spin",spinning:!0,size:"default",wrapperClassName:""},Spin.propTypes={prefixCls:PropTypes.string,className:PropTypes.string,spinning:PropTypes.bool,size:PropTypes.oneOf(["small","default","large"]),wrapperClassName:PropTypes.string,indicator:PropTypes.node};