'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _extends2 = require('babel-runtime/helpers/extends');

var _extends3 = _interopRequireDefault(_extends2);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _MainView = require('./MainView');

var _MainView2 = _interopRequireDefault(_MainView);

var _Dropload = require('./Dropload');

var _Dropload2 = _interopRequireDefault(_Dropload);

require('style-loader!./PullScroll.scss');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

// @pureRender
var PullScroll = function (_Component) {
	(0, _inherits3.default)(PullScroll, _Component);

	function PullScroll(props, context) {
		(0, _classCallCheck3.default)(this, PullScroll);

		var _this = (0, _possibleConstructorReturn3.default)(this, (PullScroll.__proto__ || Object.getPrototypeOf(PullScroll)).call(this, props, context));

		_this.state = {
			pulledY: 0, // 下拉的距离
			pullStatus: 0 // 下拉当前状态
		};
		_this.handlePullStatusChange = _this.handlePullStatusChange.bind(_this);
		_this.handlePulling = _this.handlePulling.bind(_this);
		return _this;
	}
	// PullScroll状态变更逻辑


	(0, _createClass3.default)(PullScroll, [{
		key: 'handlePullStatusChange',
		value: function handlePullStatusChange(pullStatus) {
			var pulledPauseY = this.props.pulledPauseY;
			/**
    * 0.未touchstart 
    * 1.pulling但未达到pulledPauseY 
    * 2.pulling达到pulledPauseY 
    * 3.进入pause状态 （loading）
    */

			switch (pullStatus) {
				case 0:
					this.setState({
						pullStatus: pullStatus,
						pulledY: 0
					});
					break;
				case 3:
					this.setState({
						pullStatus: pullStatus,
						pulledY: pulledPauseY
					});
					break;
				default:
					this.setState({
						pullStatus: pullStatus
					});
					break;
			}
		}
	}, {
		key: 'handlePulling',
		value: function handlePulling(pulledY) {
			this.setState({
				pulledY: pulledY
			});
		}
	}, {
		key: 'setDefault',
		value: function setDefault() {
			this.setState({
				pullStatus: 0,
				pulledY: 0
			});
			this.refs.main.setDefault();
		}
	}, {
		key: 'render',
		value: function render() {
			var _state = this.state,
			    pulledY = _state.pulledY,
			    pullStatus = _state.pullStatus;
			var _props = this.props,
			    className = _props.className,
			    isEnd = _props.isEnd,
			    style = _props.style,
			    wrapper = _props.wrapper,
			    height = _props.height,
			    pull = _props.pull,
			    scroll = _props.scroll,
			    currentPage = _props.currentPage,
			    itemArr = _props.itemArr;

			return _react2.default.createElement(
				'div',
				{
					className: (0, _classnames2.default)('rc-pull-scroll', className, wrapper && wrapper.replace('.', '')),
					style: { "minHeight": height + 'px', height: wrapper && height ? height + 'px' : "auto" }
				},
				_react2.default.createElement(_Dropload2.default, { type: 'pull', status: pullStatus, pulledY: pulledY, show: pull }),
				_react2.default.createElement(_MainView2.default, (0, _extends3.default)({}, this.props, {
					onPullStatusChange: this.handlePullStatusChange,
					onPulling: this.handlePulling,
					ref: 'main',
					isEnd: isEnd,
					currentPage: currentPage,
					itemArr: itemArr

				})),
				_react2.default.createElement(_Dropload2.default, {
					status: isEnd,
					show: scroll,
					pulledY: pulledY,
					isEnd: isEnd,
					currentPage: currentPage,
					itemArr: itemArr
				})
			);
		}
	}]);
	return PullScroll;
}(_react.Component);
// import pureRender from 'pure-render-decorator';


PullScroll.propTypes = {
	// 相关api
	className: _propTypes2.default.string, // 原项目scrollClass
	style: _propTypes2.default.object, // 原项目scrollStyle
	height: _propTypes2.default.number,
	/**
  * 容器 用于事件绑定
  * 想在微信浏览器中不露底，必传
  */
	wrapper: _propTypes2.default.string,
	/**
  * 是否运行组件，默认true，关联到触发加载数据的问题
  */
	show: _propTypes2.default.bool,
	/**
  * 是否支持下拉，默认true
  */
	pull: _propTypes2.default.bool,
	/**
  * 是否支持上滑，默认true
  */
	scroll: _propTypes2.default.bool,
	// for pull
	/**
  * 下拉结束即从状态2切换到状态3时的事件，准备去加载数据了
  */
	loadDataForPull: _propTypes2.default.func,
	/**
  * 处于pause状态即status为3时的Y方向应所在的位置
  */
	pulledPauseY: _propTypes2.default.number,
	/**
  * 下拉距离缩放比例，将会影响能够下拉的距离,可以理解为阻力
  */
	scaleY: _propTypes2.default.number,
	/**
  * 可用于上滑加载数据
  */
	// for scroll
	loadDataForScroll: _propTypes2.default.func,
	/**
  * 切换过程中判断某个值的不同来置顶
  */
	resetPrvScrollTop: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number, _propTypes2.default.bool]),
	/**
  * 用去判断是否自动执行价值数据
  */
	currentPage: _propTypes2.default.number,
	/**
  * 上“滑”加载标志
  * 有个一个状态，第一次进入自动加载，加载中，全部加载
  */
	isEnd: _propTypes2.default.number
};
PullScroll.defaultProps = {
	height: window.innerHeight,
	scaleY: 0.4,
	pulledPauseY: 60,
	isEnd: 0,
	show: true,
	pull: true,
	scroll: true
};
exports.default = PullScroll;