'use strict';

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

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

var _extends3 = _interopRequireDefault(_extends2);

var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');

var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);

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 _Core = require('./Core');

var _Core2 = _interopRequireDefault(_Core);

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

var BetterScroll = function (_Component) {
	(0, _inherits3.default)(BetterScroll, _Component);

	function BetterScroll(props, context) {
		(0, _classCallCheck3.default)(this, BetterScroll);
		return (0, _possibleConstructorReturn3.default)(this, (BetterScroll.__proto__ || Object.getPrototypeOf(BetterScroll)).call(this, props, context));
	}

	(0, _createClass3.default)(BetterScroll, [{
		key: 'componentDidMount',
		value: function componentDidMount() {
			this.betterScroller = new _Core2.default(this.refs.betterWrapper, this.props.opts);
		}
	}, {
		key: 'componentDidUpdate',
		value: function componentDidUpdate() {
			this.betterScroller.refresh();
		}
	}, {
		key: 'componentWillUnmount',
		value: function componentWillUnmount() {
			this.betterScroller.destroy();
		}
	}, {
		key: 'render',
		value: function render() {
			// 去除opts的参数，其它绑定到DOM中
			var _props = this.props,
			    opts = _props.opts,
			    className = _props.className,
			    _props$style = _props.style,
			    style = _props$style === undefined ? {} : _props$style,
			    rest = (0, _objectWithoutProperties3.default)(_props, ['opts', 'className', 'style']);

			return _react2.default.createElement(
				'div',
				(0, _extends3.default)({}, rest, { style: (0, _extends3.default)({}, style, { overflow: 'hidden' }), className: className + ' rc-bs-wrapper', ref: 'betterWrapper' }),
				_react2.default.createElement(
					'div',
					{ className: '__scroller' },
					this.props.children
				)
			);
		}
	}]);
	return BetterScroll;
}(_react.Component);

BetterScroll.propTypes = {
	// className
	// style
	// opts
};
exports.default = BetterScroll;