'use strict';

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.Block = exports.KEY_SPACE = exports.KEY_ENTER = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));

var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _classnames = _interopRequireDefault(require("classnames"));

var KEY_ENTER = 13;
exports.KEY_ENTER = KEY_ENTER;
var KEY_SPACE = 32;
exports.KEY_SPACE = KEY_SPACE;

var Block =
/*#__PURE__*/
function (_React$Component) {
  (0, _inheritsLoose2.default)(Block, _React$Component);

  function Block() {
    var _this;

    for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
      args[_key] = arguments[_key];
    }

    _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onKeyDown", function (e) {
      var _this$props = _this.props,
          onClick = _this$props.onClick,
          onKeyDown = _this$props.onKeyDown,
          preventDefaultKeyDown = _this$props.preventDefaultKeyDown;

      if (onKeyDown) {
        onKeyDown(e);
      }

      if (e.keyCode === KEY_ENTER || e.keyCode === KEY_SPACE) {
        onClick(e);

        if (preventDefaultKeyDown) {
          e.preventDefault();
        }
      }
    });
    (0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onMouseDown", function (e) {
      var onMouseDown = _this.props.onMouseDown;

      if (onMouseDown) {
        onMouseDown(e);
      }
    });
    return _this;
  }

  var _proto = Block.prototype;

  _proto.render = function render() {
    var _this$props2 = this.props,
        noOffset = _this$props2.noOffset,
        addTopOffset = _this$props2.addTopOffset,
        addLeftOffset = _this$props2.addLeftOffset,
        addRightOffset = _this$props2.addRightOffset,
        addHorizontalOffset = _this$props2.addHorizontalOffset,
        cancelTopOffset = _this$props2.cancelTopOffset,
        cancelBottomOffset = _this$props2.cancelBottomOffset,
        cancelHorizontalOffset = _this$props2.cancelHorizontalOffset,
        verticalAlign = _this$props2.verticalAlign,
        accent = _this$props2.accent,
        condensed = _this$props2.condensed,
        halfCondensed = _this$props2.halfCondensed,
        inline = _this$props2.inline,
        className = _this$props2.className,
        testAutomationId = _this$props2.testAutomationId,
        children = _this$props2.children,
        handleKeyDown = _this$props2.handleKeyDown,
        preventDefaultKeyDown = _this$props2.preventDefaultKeyDown,
        noOverflow = _this$props2.noOverflow,
        props = (0, _objectWithoutPropertiesLoose2.default)(_this$props2, ["noOffset", "addTopOffset", "addLeftOffset", "addRightOffset", "addHorizontalOffset", "cancelTopOffset", "cancelBottomOffset", "cancelHorizontalOffset", "verticalAlign", "accent", "condensed", "halfCondensed", "inline", "className", "testAutomationId", "children", "handleKeyDown", "preventDefaultKeyDown", "noOverflow"]);
    var classNames = (0, _classnames.default)(className, {
      'rc-block': !cancelBottomOffset && !noOffset && !inline,
      'rc-block-inline': inline,
      'rc-block-addTopOffset': addTopOffset,
      'rc-block-addLeftOffset': addLeftOffset,
      'rc-block-addRightOffset': addRightOffset,
      'rc-block-addHorizontalOffset': addHorizontalOffset,
      'rc-block-cancelTopOffset': cancelTopOffset,
      'rc-block-cancelBottomOffset': cancelBottomOffset,
      'rc-block-cancelHorizontalOffset': cancelHorizontalOffset,
      'rc-block-accent': accent,
      'rc-block-condensed': condensed,
      'rc-block-half-condensed': halfCondensed,
      'rc-block-vertical-center': verticalAlign === 'center' || verticalAlign === true,
      'rc-block-vertical-bottom': verticalAlign === 'bottom',
      'rc-block-noOverflow': noOverflow
    });

    if (handleKeyDown) {
      props = Object.assign({}, props, {
        onMouseDown: this.onMouseDown,
        onKeyDown: this.onKeyDown
      });
    }

    return _react.default.createElement("div", (0, _extends2.default)({
      className: classNames,
      "data-test-automation-id": testAutomationId
    }, props), children);
  };

  return Block;
}(_react.default.Component);

exports.Block = Block;
(0, _defineProperty2.default)(Block, "propTypes", {
  noOffset: _propTypes.default.bool,
  addTopOffset: _propTypes.default.bool,
  addLeftOffset: _propTypes.default.bool,
  addRightOffset: _propTypes.default.bool,
  addHorizontalOffset: _propTypes.default.bool,
  cancelTopOffset: _propTypes.default.bool,
  cancelBottomOffset: _propTypes.default.bool,
  cancelHorizontalOffset: _propTypes.default.bool,
  accent: _propTypes.default.bool,
  condensed: _propTypes.default.bool,
  halfCondensed: _propTypes.default.bool,
  inline: _propTypes.default.bool,
  verticalAlign: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.bool]),
  children: _propTypes.default.node,
  className: _propTypes.default.string,
  testAutomationId: _propTypes.default.string,
  onClick: _propTypes.default.func,
  onKeyDown: _propTypes.default.func,
  onMouseDown: _propTypes.default.func,
  handleKeyDown: _propTypes.default.bool,
  preventDefaultKeyDown: _propTypes.default.bool,
  noOverflow: _propTypes.default.bool
});
(0, _defineProperty2.default)(Block, "defaultProps", {
  noOffset: false,
  addTopOffset: false,
  addLeftOffset: false,
  addRightOffset: false,
  addHorizontalOffset: false,
  cancelTopOffset: false,
  cancelBottomOffset: false,
  cancelHorizontalOffset: false,
  accent: false,
  condensed: false,
  halfCondensed: false,
  inline: false,
  verticalAlign: false,
  children: null,
  className: null,
  testAutomationId: null,
  onClick: function onClick(e) {
    return e;
  },
  onKeyDown: null,
  onMouseDown: null,
  handleKeyDown: false,
  preventDefaultKeyDown: true,
  noOverflow: false
});