var _excluded = ["block", "children", "disabled", "icon", "iconRight", "loading", "size", "type", "variant"],
  _excluded2 = ["block", "children", "disabled", "href", "icon", "iconRight", "size", "variant"];
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
import React from 'react';
import { useEventListener } from '../_hooks/EventListener';
import { mergeRefs } from '../_utils/mergeRefs';
import { StyledButton, StyledContent, StyledLabel, StyledLinkButton, StyledSpinner } from './Button.styles';
var ButtonContent = function ButtonContent(_ref) {
  var children = _ref.children,
    icon = _ref.icon,
    iconRight = _ref.iconRight,
    size = _ref.size,
    variant = _ref.variant;
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(StyledContent, null, /*#__PURE__*/React.isValidElement(icon) ? /*#__PURE__*/React.cloneElement(icon, _defineProperty({}, 'data-icon-prop', 'true')) : null, React.Children.map(children, function (child) {
    return /*#__PURE__*/React.createElement(StyledLabel, null, child);
  }), /*#__PURE__*/React.isValidElement(iconRight) ? /*#__PURE__*/React.cloneElement(iconRight, _defineProperty({}, 'data-icon-prop', 'true')) : null), /*#__PURE__*/React.createElement(StyledSpinner, {
    size: size === 'lg' ? 'md' : 'sm',
    color: variant === 'primary' ? 'white' : 'gray15'
  }));
};

/**

 We use buttons to link to other pages or to trigger an action.
 Buttons clearly define what happens when a user clicks it.

 @since 10.19.0

 @see [Storybook](https://procore.github.io/core/core-react/latest/?path=/story/demos-button--demo)

 @see [Design Guidelines](https://design.procore.com/button)

 */
export var Button = /*#__PURE__*/React.forwardRef(function Button(_ref2, ref) {
  var _ref2$block = _ref2.block,
    block = _ref2$block === void 0 ? false : _ref2$block,
    children = _ref2.children,
    _ref2$disabled = _ref2.disabled,
    disabled = _ref2$disabled === void 0 ? false : _ref2$disabled,
    icon = _ref2.icon,
    iconRight = _ref2.iconRight,
    _ref2$loading = _ref2.loading,
    loading = _ref2$loading === void 0 ? false : _ref2$loading,
    _ref2$size = _ref2.size,
    size = _ref2$size === void 0 ? 'md' : _ref2$size,
    _ref2$type = _ref2.type,
    type = _ref2$type === void 0 ? 'button' : _ref2$type,
    _ref2$variant = _ref2.variant,
    variant = _ref2$variant === void 0 ? 'primary' : _ref2$variant,
    props = _objectWithoutProperties(_ref2, _excluded);
  return /*#__PURE__*/React.createElement(StyledButton, _extends({
    "aria-busy": loading || undefined,
    "data-a11y-skip": variant === 'primary' ? 'color-contrast' : undefined,
    tabIndex: 0
  }, props, {
    $block: block,
    disabled: disabled || loading,
    $loading: loading,
    $size: size,
    $variant: variant,
    type: type,
    ref: ref
  }), /*#__PURE__*/React.createElement(ButtonContent, {
    icon: icon,
    iconRight: iconRight,
    size: size,
    variant: variant
  }, children));
});
export var LinkButton = /*#__PURE__*/React.forwardRef(function LinkButton(_ref3, ref) {
  var _ref3$block = _ref3.block,
    block = _ref3$block === void 0 ? false : _ref3$block,
    children = _ref3.children,
    disabled_ = _ref3.disabled,
    href_ = _ref3.href,
    icon = _ref3.icon,
    iconRight = _ref3.iconRight,
    _ref3$size = _ref3.size,
    size = _ref3$size === void 0 ? 'md' : _ref3$size,
    _ref3$variant = _ref3.variant,
    variant = _ref3$variant === void 0 ? 'primary' : _ref3$variant,
    props = _objectWithoutProperties(_ref3, _excluded2);
  var innerRef = React.useRef(null);
  var mimicButtonRole = function mimicButtonRole(e) {
    var key = e.key;
    if (['Enter', 'Spacebar', ' '].indexOf(key) >= 0) {
      var _innerRef$current;
      // Prevents the page to scroll when "space" is pressed
      e.preventDefault();
      (_innerRef$current = innerRef.current) === null || _innerRef$current === void 0 ? void 0 : _innerRef$current.click();
    }
  };
  useEventListener({
    event: 'keydown',
    handler: mimicButtonRole,
    scope: innerRef
  });
  var disabled = disabled_ || !href_;
  var href = disabled ? undefined : href_;
  return /*#__PURE__*/React.createElement(StyledLinkButton, _extends({
    "data-a11y-skip": variant === 'primary' ? 'color-contrast' : undefined
  }, props, {
    role: "button",
    "aria-disabled": disabled,
    href: href,
    $disabled: disabled,
    $block: block,
    $size: size,
    $variant: variant,
    ref: mergeRefs(ref, innerRef)
  }), /*#__PURE__*/React.createElement(ButtonContent, {
    icon: icon,
    iconRight: iconRight,
    size: size,
    variant: variant
  }, children));
});
//# sourceMappingURL=Button.js.map