import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _possibleConstructorReturn from "@babel/runtime/helpers/esm/possibleConstructorReturn";
import _getPrototypeOf from "@babel/runtime/helpers/esm/getPrototypeOf";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

/**
 * 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 =
/*#__PURE__*/
function (_React$PureComponent) {
  _inherits(ArrowBtn, _React$PureComponent);

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

    return _possibleConstructorReturn(this, _getPrototypeOf(ArrowBtn).apply(this, arguments));
  }

  _createClass(ArrowBtn, [{
    key: "componentDidMount",
    value: function componentDidMount() {
      var _this$props = this.props,
          imgWidth = _this$props.imgWidth,
          arrowClick = _this$props.arrowClick,
          direction = _this$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 _this = this;

      var _this$props2 = this.props,
          arrowDisplay = _this$props2.arrowDisplay,
          direction = _this$props2.direction;

      var _ref = direction === 'left-arrow' ? 'prevBtn' : 'nextBtn';

      return React.createElement("div", {
        className: "".concat(direction, "-container"),
        ref: function ref(e) {
          return _this[_ref] = e;
        }
      }, arrowDisplay && React.createElement("div", {
        className: classNames('arrow', direction)
      }));
    }
  }]);

  return ArrowBtn;
}(React.PureComponent);

_defineProperty(ArrowBtn, "propTypes", {
  arrowDisplay: PropTypes.bool,
  direction: PropTypes.string
});

export default ArrowBtn;