'use strict';

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
var React = require('react');
var classnames = require('classnames');
var reactRouterDom = require('react-router-dom');
var Spinner = require('./Spinner.js');
var Tooltip = require('./Tooltip.js');
var jsxRuntime = require('react/jsx-runtime');
require('@babel/runtime/helpers/slicedToArray');
require('@tippyjs/react');
require('tippy.js');
require('@bigbinary/neeto-hotkeys');
require('./overlayManager.js');
require('@babel/runtime/helpers/classCallCheck');
require('@babel/runtime/helpers/createClass');
require('@bigbinary/neeto-cist');
require('qs');
require('ramda');
require('./index-BgzkP01c.js');
require('@babel/runtime/helpers/toConsumableArray');
require('dayjs');
require('dayjs/plugin/localeData');
require('dayjs/plugin/utc');
require('dayjs/plugin/weekday');
require('dayjs/plugin/weekOfYear');
require('i18next');
require('./usePrefersReducedMotion-D2Ck84HM.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefault(_defineProperty);
var _objectWithoutProperties__default = /*#__PURE__*/_interopDefault(_objectWithoutProperties);
var React__default = /*#__PURE__*/_interopDefault(React);
var classnames__default = /*#__PURE__*/_interopDefault(classnames);

var _excluded = ["icon", "iconPosition", "iconSize", "label", "loading", "onClick", "to", "type", "style", "fullWidth", "className", "disabled", "size", "href", "tooltipProps", "children"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty__default.default(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var BUTTON_STYLES = {
  primary: "primary",
  secondary: "secondary",
  tertiary: "tertiary",
  danger: "danger",
  danger_text: "danger-text",
  text: "text",
  link: "link"
};
var SIZES = {
  medium: "medium",
  large: "large"
};
var ICON_POSITIONS = {
  left: "left",
  right: "right"
};
var BUTTON_TYPES = {
  button: "button"};
var Button = /*#__PURE__*/React__default.default.forwardRef(function (_ref, ref) {
  var _ref$icon = _ref.icon,
    icon = _ref$icon === void 0 ? null : _ref$icon,
    _ref$iconPosition = _ref.iconPosition,
    iconPosition = _ref$iconPosition === void 0 ? ICON_POSITIONS.right : _ref$iconPosition,
    _ref$iconSize = _ref.iconSize,
    iconSize = _ref$iconSize === void 0 ? 16 : _ref$iconSize,
    _ref$label = _ref.label,
    label = _ref$label === void 0 ? "" : _ref$label,
    _ref$loading = _ref.loading,
    loading = _ref$loading === void 0 ? false : _ref$loading,
    _ref$onClick = _ref.onClick,
    onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
    _ref$to = _ref.to,
    to = _ref$to === void 0 ? "" : _ref$to,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? BUTTON_TYPES.button : _ref$type,
    _ref$style = _ref.style,
    style = _ref$style === void 0 ? BUTTON_STYLES.primary : _ref$style,
    _ref$fullWidth = _ref.fullWidth,
    fullWidth = _ref$fullWidth === void 0 ? false : _ref$fullWidth,
    _ref$className = _ref.className,
    className = _ref$className === void 0 ? "" : _ref$className,
    _ref$disabled = _ref.disabled,
    disabled = _ref$disabled === void 0 ? false : _ref$disabled,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? SIZES.medium : _ref$size,
    _ref$href = _ref.href,
    href = _ref$href === void 0 ? "" : _ref$href,
    _ref$tooltipProps = _ref.tooltipProps,
    tooltipProps = _ref$tooltipProps === void 0 ? null : _ref$tooltipProps,
    children = _ref.children,
    otherProps = _objectWithoutProperties__default.default(_ref, _excluded);
  var Parent = "button";
  var elementSpecificProps = {
    type: type
  };
  var renderLabel = label || children;
  if (!disabled) {
    if (to) {
      Parent = reactRouterDom.Link;
      elementSpecificProps = {
        to: to
      };
    } else if (href) {
      Parent = "a";
      elementSpecificProps = {
        href: href
      };
    }
  }
  var handleClick = function handleClick(e) {
    if (loading || disabled) return;
    onClick(e);
  };
  var Icon = typeof icon === "string" ? function () {
    return /*#__PURE__*/jsxRuntime.jsx("i", {
      className: classnames__default.default("neeto-ui-btn__icon", [icon]),
      "data-testid": "class-icon"
    });
  } : icon || React__default.default.Fragment;
  return /*#__PURE__*/jsxRuntime.jsx(Tooltip, _objectSpread(_objectSpread({
    disabled: !tooltipProps
  }, tooltipProps), {}, {
    children: /*#__PURE__*/jsxRuntime.jsxs(Parent, _objectSpread(_objectSpread({
      className: classnames__default.default("neeto-ui-btn", [className], {
        "neeto-ui-btn--style-primary": style === BUTTON_STYLES.primary,
        "neeto-ui-btn--style-secondary": style === BUTTON_STYLES.secondary,
        "neeto-ui-btn--style-tertiary": style === BUTTON_STYLES.tertiary,
        "neeto-ui-btn--style-danger": style === BUTTON_STYLES.danger,
        "neeto-ui-btn--style-danger-text": style === BUTTON_STYLES.danger_text,
        "neeto-ui-btn--style-text": style === BUTTON_STYLES.text,
        "neeto-ui-btn--style-link": style === BUTTON_STYLES.link,
        "neeto-ui-btn--size-medium": size === SIZES.medium,
        "neeto-ui-btn--size-large": size === SIZES.large,
        "neeto-ui-btn--width-full": fullWidth,
        "neeto-ui-btn--icon-left": iconPosition === ICON_POSITIONS.left,
        "neeto-ui-btn--icon-only": !renderLabel,
        "neeto-ui-btn--loading": loading,
        disabled: disabled
      }),
      onClick: handleClick
    }, _objectSpread(_objectSpread({
      disabled: disabled,
      ref: ref
    }, elementSpecificProps), otherProps)), {}, {
      children: [renderLabel && /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "neeto-ui-btn__label",
        children: renderLabel
      }), icon && /*#__PURE__*/jsxRuntime.jsx(Icon, {
        "aria-hidden": "true",
        className: "neeto-ui-btn__icon",
        size: iconSize
      }), loading && /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "neeto-ui-btn__spinner",
        children: /*#__PURE__*/jsxRuntime.jsx(Spinner, {
          "aria-hidden": "true",
          size: "small"
        })
      })]
    }))
  }));
});
Button.displayName = "Button";

module.exports = Button;
//# sourceMappingURL=Button.js.map
