"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var _extends2=require("babel-runtime/helpers/extends"),_extends3=_interopRequireDefault(_extends2),_classCallCheck2=require("babel-runtime/helpers/classCallCheck"),_classCallCheck3=_interopRequireDefault(_classCallCheck2),_createClass2=require("babel-runtime/helpers/createClass"),_createClass3=_interopRequireDefault(_createClass2),_possibleConstructorReturn2=require("babel-runtime/helpers/possibleConstructorReturn"),_possibleConstructorReturn3=_interopRequireDefault(_possibleConstructorReturn2),_inherits2=require("babel-runtime/helpers/inherits"),_inherits3=_interopRequireDefault(_inherits2),_react=require("react"),React=_interopRequireWildcard(_react),_omit=require("omit.js"),_omit2=_interopRequireDefault(_omit),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames);function _interopRequireWildcard(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function getNumberArray(e){return e?e.toString().split("").reverse().map(function(e){return Number(e)}):[]}var ScrollNumber=function(e){function r(e){(0,_classCallCheck3.default)(this,r);var t=(0,_possibleConstructorReturn3.default)(this,(r.__proto__||Object.getPrototypeOf(r)).call(this,e));return t.state={animateStarted:!0,count:e.count},t}return(0,_inherits3.default)(r,e),(0,_createClass3.default)(r,[{key:"getPositionByNum",value:function(e,t){if(this.state.animateStarted)return 10+e;var r=getNumberArray(this.state.count)[t],n=getNumberArray(this.lastCount)[t];return this.state.count>this.lastCount?n<=r?10+e:20+e:r<=n?10+e:e}},{key:"componentWillReceiveProps",value:function(e){var t=this;if("count"in e){if(this.state.count===e.count)return;this.lastCount=this.state.count,this.setState({animateStarted:!0},function(){setTimeout(function(){t.setState({animateStarted:!1,count:e.count},function(){var e=t.props.onAnimated;e&&e()})},5)})}}},{key:"renderNumberList",value:function(e){for(var t=[],r=0;r<30;r++){var n=e===r?"current":"";t.push(React.createElement("p",{key:r.toString(),className:n},r%10))}return t}},{key:"renderCurrentNumber",value:function(e,t){var r=this.getPositionByNum(e,t),n=this.state.animateStarted||void 0===getNumberArray(this.lastCount)[t];return(0,_react.createElement)("span",{className:this.props.prefixCls+"-only",style:{transition:n&&"none",msTransform:"translateY("+100*-r+"%)",WebkitTransform:"translateY("+100*-r+"%)",transform:"translateY("+100*-r+"%)"},key:t},this.renderNumberList(r))}},{key:"renderNumberElement",value:function(){var r=this,e=this.state;return!e.count||isNaN(e.count)?e.count:getNumberArray(e.count).map(function(e,t){return r.renderCurrentNumber(e,t)}).reverse()}},{key:"render",value:function(){var e=this.props,t=e.prefixCls,r=e.className,n=e.style,s=e.title,a=e.component,u=void 0===a?"sup":a,i=(0,_omit2.default)(this.props,["count","onAnimated","component","prefixCls"]),o=(0,_extends3.default)({},i,{className:(0,_classnames2.default)(t,r),title:s});return n&&n.borderColor&&(o.style.boxShadow="0 0 0 1px "+n.borderColor+" inset"),(0,_react.createElement)(u,o,this.renderNumberElement())}}]),r}(_react.Component);(exports.default=ScrollNumber).defaultProps={prefixCls:"dt-scroll-number",count:null,onAnimated:function(){}},module.exports=exports.default;