"use strict";

exports.__esModule = true;
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _noop = _interopRequireDefault(require("lodash/fp/noop"));
var _proptypes = require("../../util/proptypes");
var _link = _interopRequireDefault(require("../link"));
var _style = _interopRequireDefault(require("./style.css"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
const ButtonContent = props => {
  const {
    color,
    submitValue,
    disabled,
    download,
    href,
    target,
    onClick,
    className,
    children,
    type,
    style,
    'data-name': dataName,
    'aria-label': ariaLabel,
    'data-testid': dataTestid,
    useButtonTag,
    buttonRef,
    'data-for': dataFor,
    'data-tooltip-place': dataTooltipPlace,
    'data-tip': dataTip,
    onKeyDown = _noop.default,
    onMouseLeave = _noop.default,
    onMouseOver = _noop.default
  } = props;
  const anchorClassName = disabled && `${className} ${_style.default.disabledAnchor}` || className;
  const anchorOnClick = disabled && null || onClick;
  const anchorHref = disabled && null || href;
  const inputClassName = disabled && `${className} ${_style.default.buttonDisabled}` || className;
  switch (type) {
    case 'link':
      return /*#__PURE__*/_react.default.createElement(_link.default, {
        "data-name": dataName,
        href: anchorHref,
        download: download,
        onClick: anchorOnClick,
        target: target,
        className: anchorClassName,
        style: style,
        "aria-label": ariaLabel,
        "data-testid": dataTestid
      }, submitValue || children || 'submit');
    case 'a':
      return /*#__PURE__*/_react.default.createElement("a", {
        "data-name": dataName,
        href: anchorHref,
        target: target,
        className: anchorClassName,
        onClick: anchorOnClick,
        style: style,
        "data-testid": dataTestid
      }, submitValue || children);
    case 'button':
      if (useButtonTag) return /*#__PURE__*/_react.default.createElement("button", {
        ref: buttonRef,
        type: "button",
        "data-for": dataFor,
        "data-tooltip-place": dataTooltipPlace,
        "data-tip": dataTip,
        "data-name": dataName,
        "data-testid": dataTestid,
        "aria-label": ariaLabel.favorite,
        className: className,
        onClick: onClick,
        style: style,
        onKeyDown: onKeyDown,
        onMouseLeave: onMouseLeave,
        onMouseOver: onMouseOver,
        tabIndex: 0
      }, children);
    // falls through in case type is button BUT no button tag is needed, for retro-compatibility
    default:
      {
        return /*#__PURE__*/_react.default.createElement("input", {
          "data-name": dataName,
          type: type,
          value: submitValue,
          disabled: disabled,
          onClick: onClick,
          className: inputClassName,
          "data-testid": dataTestid,
          style: {
            color,
            ...style
          }
        });
      }
  }
};
ButtonContent.propTypes = process.env.NODE_ENV !== "production" ? {
  color: _proptypes.ColorPropType,
  submitValue: _propTypes.default.string,
  disabled: _propTypes.default.bool,
  href: _propTypes.default.string,
  download: _propTypes.default.bool,
  target: _propTypes.default.oneOf(['_self', '_blank', '_parent', '_top']),
  type: _propTypes.default.string,
  children: _propTypes.default.node,
  className: _propTypes.default.string,
  style: _propTypes.default.shape({}),
  'data-name': _propTypes.default.string,
  'aria-label': _propTypes.default.string,
  'data-testid': _propTypes.default.string,
  useButtonTag: _propTypes.default.bool,
  // event handlers
  onClick: _propTypes.default.func,
  onKeyDown: _propTypes.default.func,
  onMouseLeave: _propTypes.default.func,
  onMouseOver: _propTypes.default.func,
  // for ReactTooltip handling
  buttonRef: _propTypes.default.shape({}),
  'data-for': _propTypes.default.string,
  'data-tooltip-place': _propTypes.default.string,
  'data-tip': _propTypes.default.bool
} : {};
const Button = props => {
  const {
    className,
    buttonContentClassName,
    isLinkDisabled,
    type = 'submit',
    children,
    useWrapper = true
  } = props;
  const buttonWrapperClassNames = (0, _react.useMemo)(() => isLinkDisabled && (0, _classnames.default)([_style.default.disabledAnchor, className]) || (0, _classnames.default)([_style.default.button, className]), [className, isLinkDisabled]);
  const contentClassName = (0, _react.useMemo)(() => buttonContentClassName ? buttonContentClassName : _style.default.buttonContent, [buttonContentClassName]);
  return useWrapper ? /*#__PURE__*/_react.default.createElement("div", {
    className: buttonWrapperClassNames
  }, /*#__PURE__*/_react.default.createElement(ButtonContent, _extends({}, props, {
    type: type,
    className: contentClassName
  }), children)) : /*#__PURE__*/_react.default.createElement(ButtonContent, _extends({}, props, {
    type: type,
    className: contentClassName
  }), children);
};
Button.propTypes = process.env.NODE_ENV !== "production" ? {
  isLinkDisabled: _propTypes.default.bool,
  useWrapper: _propTypes.default.bool,
  buttonContentClassName: _propTypes.default.string,
  ...ButtonContent.propTypes
} : {};
var _default = exports.default = Button;
//# sourceMappingURL=index.js.map