"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

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

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

var _reactOuiIcons = _interopRequireDefault(require("react-oui-icons"));

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

var _accessibility = require("../../utils/accessibility");

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

var ButtonIcon = function ButtonIcon(_ref) {
  var buttonRef = _ref.buttonRef,
      iconFill = _ref.iconFill,
      iconName = _ref.iconName,
      isDisabled = _ref.isDisabled,
      onClick = _ref.onClick,
      size = _ref.size,
      style = _ref.style,
      testSection = _ref.testSection,
      title = _ref.title;
  // ensure valid fillColor name (in the case that propType errors are ignored)
  var fillColor = iconFill && Object.keys(_accessibility.FILL_COLOR_MAP).includes(iconFill) ? _accessibility.FILL_COLOR_MAP[iconFill] : null;

  function handleOnClick(event) {
    if (isDisabled) {
      return;
    }

    onClick(event);
  }

  return _react["default"].createElement("button", {
    className: (0, _classnames["default"])('oui-button', 'oui-button-icon', "oui-button-icon__".concat(size), "oui-button--".concat(style)),
    "data-oui-component": true,
    "data-test-section": testSection,
    disabled: isDisabled,
    onClick: handleOnClick,
    ref: buttonRef,
    title: title
  }, _react["default"].createElement(_reactOuiIcons["default"], {
    name: iconName,
    size: size,
    fill: fillColor
  }));
};

ButtonIcon.propTypes = {
  /** React ref to the underlying button component */
  buttonRef: _propTypes["default"].oneOfType([_propTypes["default"].func, _propTypes["default"].shape({
    current: _propTypes["default"].instanceOf(Element)
  })]),

  /**
   *  Color to use for the fill of the icon
   */
  iconFill: _propTypes["default"].oneOf(Object.keys(_accessibility.FILL_COLOR_MAP)),

  /**
   *  Name of the icon to use
   */
  iconName: _propTypes["default"].string.isRequired,

  /**
   * Prevent users from interacting with the button
   */
  isDisabled: _propTypes["default"].bool,

  /**
   *  Function to perform when the close button is clicked.
   */
  onClick: _propTypes["default"].func.isRequired,

  /**
   *  Size of the button, medium by default
   */
  size: _propTypes["default"].oneOf(['small', 'medium', 'large']),

  /**
   *  Various style options
   */
  style: _propTypes["default"].oneOf(['highlight', 'danger', 'danger-outline', 'outline', 'plain']),

  /**
   * Hook for automated JavaScript tests
   */
  testSection: _propTypes["default"].string,

  /**
   *  Title of the button used on hover and for screen readers
   */
  title: _propTypes["default"].string.isRequired
};
ButtonIcon.defaultProps = {
  iconName: 'add',
  onClick: function onClick() {},
  size: 'medium',
  title: ''
};
var _default = ButtonIcon;
exports["default"] = _default;