'use strict';

import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/inheritsLoose";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
export var KEY_ENTER = 13;
export var KEY_SPACE = 32;
export var Block =
/*#__PURE__*/
function (_React$Component) {
  _inheritsLoose(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;

    _defineProperty(_assertThisInitialized(_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();
        }
      }
    });

    _defineProperty(_assertThisInitialized(_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 = _objectWithoutPropertiesLoose(_this$props2, ["noOffset", "addTopOffset", "addLeftOffset", "addRightOffset", "addHorizontalOffset", "cancelTopOffset", "cancelBottomOffset", "cancelHorizontalOffset", "verticalAlign", "accent", "condensed", "halfCondensed", "inline", "className", "testAutomationId", "children", "handleKeyDown", "preventDefaultKeyDown", "noOverflow"]);

    var classNames = classnames(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.createElement("div", _extends({
      className: classNames,
      "data-test-automation-id": testAutomationId
    }, props), children);
  };

  return Block;
}(React.Component);

_defineProperty(Block, "propTypes", {
  noOffset: PropTypes.bool,
  addTopOffset: PropTypes.bool,
  addLeftOffset: PropTypes.bool,
  addRightOffset: PropTypes.bool,
  addHorizontalOffset: PropTypes.bool,
  cancelTopOffset: PropTypes.bool,
  cancelBottomOffset: PropTypes.bool,
  cancelHorizontalOffset: PropTypes.bool,
  accent: PropTypes.bool,
  condensed: PropTypes.bool,
  halfCondensed: PropTypes.bool,
  inline: PropTypes.bool,
  verticalAlign: PropTypes.oneOfType([PropTypes.string, PropTypes.bool]),
  children: PropTypes.node,
  className: PropTypes.string,
  testAutomationId: PropTypes.string,
  onClick: PropTypes.func,
  onKeyDown: PropTypes.func,
  onMouseDown: PropTypes.func,
  handleKeyDown: PropTypes.bool,
  preventDefaultKeyDown: PropTypes.bool,
  noOverflow: PropTypes.bool
});

_defineProperty(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
});