"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),_rcAnimate=require("rc-animate"),_rcAnimate2=_interopRequireDefault(_rcAnimate),_addEventListener=require("rc-util/lib/Dom/addEventListener"),_addEventListener2=_interopRequireDefault(_addEventListener),_classnames=require("classnames"),_classnames2=_interopRequireDefault(_classnames),_omit=require("omit.js"),_omit2=_interopRequireDefault(_omit),_getScroll=require("../_util/getScroll"),_getScroll2=_interopRequireDefault(_getScroll),_getRequestAnimationFrame=require("../_util/getRequestAnimationFrame"),_getRequestAnimationFrame2=_interopRequireDefault(_getRequestAnimationFrame);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}}var reqAnimFrame=(0,_getRequestAnimationFrame2.default)(),easeInOutCubic=function(e,t,r,i){var l=r-t;return(e/=i/2)<1?l/2*e*e*e+t:l/2*((e-=2)*e*e+2)+t};function noop(){}function getDefaultTarget(){return window}var BackTop=function(e){function t(e){(0,_classCallCheck3.default)(this,t);var n=(0,_possibleConstructorReturn3.default)(this,(t.__proto__||Object.getPrototypeOf(t)).call(this,e));return n.getCurrentScrollTop=function(){var e=(n.props.target||getDefaultTarget)();return e===window?window.pageYOffset||document.body.scrollTop||document.documentElement.scrollTop:e.scrollTop},n.scrollToTop=function(e){var r=n.getCurrentScrollTop(),i=Date.now();reqAnimFrame(function e(){var t=Date.now()-i;n.setScrollTop(easeInOutCubic(t,r,0,450)),t<450&&reqAnimFrame(e)}),(n.props.onClick||noop)(e)},n.handleScroll=function(){var e=n.props,t=e.visibilityHeight,r=e.target,i=void 0===r?getDefaultTarget:r,l=(0,_getScroll2.default)(i(),!0);n.setState({visible:t<l})},n.state={visible:!1},n}return(0,_inherits3.default)(t,e),(0,_createClass3.default)(t,[{key:"setScrollTop",value:function(e){var t=(this.props.target||getDefaultTarget)();t===window?(document.body.scrollTop=e,document.documentElement.scrollTop=e):t.scrollTop=e}},{key:"componentDidMount",value:function(){var e=this.props.target||getDefaultTarget;this.scrollEvent=(0,_addEventListener2.default)(e(),"scroll",this.handleScroll),this.handleScroll()}},{key:"componentWillUnmount",value:function(){this.scrollEvent&&this.scrollEvent.remove()}},{key:"render",value:function(){var e=this.props,t=e.prefixCls,r=void 0===t?"dt-back-top":t,i=e.className,l=void 0===i?"":i,n=e.children,a=(0,_classnames2.default)(r,l),o=React.createElement("div",{className:r+"-content"},React.createElement("div",{className:r+"-icon"})),s=(0,_omit2.default)(this.props,["prefixCls","className","children","visibilityHeight","target"]),u=this.state.visible?React.createElement("div",(0,_extends3.default)({},s,{className:a,onClick:this.scrollToTop}),n||o):null;return React.createElement(_rcAnimate2.default,{component:"",transitionName:"fade"},u)}}]),t}(React.Component);(exports.default=BackTop).defaultProps={visibilityHeight:400},module.exports=exports.default;