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); }
import React, { useMemo } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import noop from 'lodash/fp/noop';
import { ColorPropType } from '../../util/proptypes';
import Link from '../link';
import cssStyle from './style.css';
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,
    onMouseLeave = noop,
    onMouseOver = noop
  } = props;
  const anchorClassName = disabled && `${className} ${cssStyle.disabledAnchor}` || className;
  const anchorOnClick = disabled && null || onClick;
  const anchorHref = disabled && null || href;
  const inputClassName = disabled && `${className} ${cssStyle.buttonDisabled}` || className;
  switch (type) {
    case 'link':
      return /*#__PURE__*/React.createElement(Link, {
        "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.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.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.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: ColorPropType,
  submitValue: PropTypes.string,
  disabled: PropTypes.bool,
  href: PropTypes.string,
  download: PropTypes.bool,
  target: PropTypes.oneOf(['_self', '_blank', '_parent', '_top']),
  type: PropTypes.string,
  children: PropTypes.node,
  className: PropTypes.string,
  style: PropTypes.shape({}),
  'data-name': PropTypes.string,
  'aria-label': PropTypes.string,
  'data-testid': PropTypes.string,
  useButtonTag: PropTypes.bool,
  // event handlers
  onClick: PropTypes.func,
  onKeyDown: PropTypes.func,
  onMouseLeave: PropTypes.func,
  onMouseOver: PropTypes.func,
  // for ReactTooltip handling
  buttonRef: PropTypes.shape({}),
  'data-for': PropTypes.string,
  'data-tooltip-place': PropTypes.string,
  'data-tip': PropTypes.bool
} : {};
const Button = props => {
  const {
    className,
    buttonContentClassName,
    isLinkDisabled,
    type = 'submit',
    children,
    useWrapper = true
  } = props;
  const buttonWrapperClassNames = useMemo(() => isLinkDisabled && classnames([cssStyle.disabledAnchor, className]) || classnames([cssStyle.button, className]), [className, isLinkDisabled]);
  const contentClassName = useMemo(() => buttonContentClassName ? buttonContentClassName : cssStyle.buttonContent, [buttonContentClassName]);
  return useWrapper ? /*#__PURE__*/React.createElement("div", {
    className: buttonWrapperClassNames
  }, /*#__PURE__*/React.createElement(ButtonContent, _extends({}, props, {
    type: type,
    className: contentClassName
  }), children)) : /*#__PURE__*/React.createElement(ButtonContent, _extends({}, props, {
    type: type,
    className: contentClassName
  }), children);
};
Button.propTypes = process.env.NODE_ENV !== "production" ? {
  isLinkDisabled: PropTypes.bool,
  useWrapper: PropTypes.bool,
  buttonContentClassName: PropTypes.string,
  ...ButtonContent.propTypes
} : {};
export default Button;
//# sourceMappingURL=index.js.map