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 _jsxFileName = 'src/carousel/ArrowBtn.jsx';
/**
 * arrowBtn.jsx
 *
 * @Author: apple
 * @Date: 2017/10/10 16:46
 */

import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';

/**
 * @ignore
 * */

var ArrowBtn = function (_React$PureComponent) {
    _inherits(ArrowBtn, _React$PureComponent);

    function ArrowBtn() {
        _classCallCheck(this, ArrowBtn);

        return _possibleConstructorReturn(this, (ArrowBtn.__proto__ || Object.getPrototypeOf(ArrowBtn)).apply(this, arguments));
    }

    _createClass(ArrowBtn, [{
        key: 'componentDidMount',
        value: function componentDidMount() {
            var _props = this.props,
                imgWidth = _props.imgWidth,
                arrowClick = _props.arrowClick,
                direction = _props.direction;

            var ref = 'prevBtn';
            var movePace = imgWidth;
            var nextBool = false;
            if (direction === 'right-arrow') {
                ref = 'nextBtn';
                movePace = -imgWidth;
                nextBool = true;
            }
            this[ref].onclick = function () {
                arrowClick(movePace, nextBool);
            };
        }
    }, {
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props2 = this.props,
                arrowDisplay = _props2.arrowDisplay,
                direction = _props2.direction;

            var _ref = direction === 'left-arrow' ? 'prevBtn' : 'nextBtn';
            return React.createElement(
                'div',
                { className: direction + '-container', ref: function ref(e) {
                        return _this2[_ref] = e;
                    }, __source: {
                        fileName: _jsxFileName,
                        lineNumber: 40
                    },
                    __self: this
                },
                arrowDisplay && React.createElement('div', { className: classNames('arrow', direction), __source: {
                        fileName: _jsxFileName,
                        lineNumber: 41
                    },
                    __self: this
                })
            );
        }
    }]);

    return ArrowBtn;
}(React.PureComponent);

ArrowBtn.propTypes = {
    arrowDisplay: PropTypes.bool,
    direction: PropTypes.string
};


export default ArrowBtn;