'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var React = require('react');
var PrimitiveButton = require('../primitives/PrimitiveButton/PrimitiveButton.js');
var PrimitiveAnchor = require('../primitives/PrimitiveAnchor/PrimitiveAnchor.js');
var AvatarLayout = require('../avatarLayout/AvatarLayout.js');
var ProcessIndicator = require('../processIndicator/ProcessIndicator.js');
var clsx = require('clsx');
require('../common/theme.js');
require('../common/direction.js');
require('@transferwise/neptune-tokens');
require('../common/propsValues/control.js');
require('../common/propsValues/size.js');
var typography = require('../common/propsValues/typography.js');
require('../common/propsValues/width.js');
require('../common/propsValues/type.js');
require('../common/propsValues/dateMode.js');
require('../common/propsValues/monthFormat.js');
require('../common/propsValues/position.js');
require('../common/propsValues/layouts.js');
require('../common/propsValues/status.js');
require('../common/propsValues/sentiment.js');
require('../common/propsValues/profileType.js');
require('../common/propsValues/variant.js');
require('../common/propsValues/scroll.js');
require('../common/propsValues/markdownNodeType.js');
require('../common/fileType.js');
require('@transferwise/formatting');
require('@transferwise/icons');
require('react-intl');
require('../common/closeButton/CloseButton.messages.js');
var jsxRuntime = require('react/jsx-runtime');
var Body = require('../body/Body.js');

/* eslint-disable react/display-name */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
const Button = /*#__PURE__*/React.forwardRef(({
  as,
  children,
  className,
  size = 'lg',
  href,
  disabled = false,
  priority = 'primary',
  sentiment = 'default',
  addonStart,
  addonEnd,
  // @ts-expect-error NewButtonProps has `type` prop
  type = 'button',
  loading = false,
  block = false,
  v2,
  ...props
}, ref) => {
  const classNames = clsx.clsx('wds-Button', {
    [`wds-Button--block`]: block,
    [`wds-Button--disabled`]: disabled,
    [`wds-Button--loading`]: loading
  }, `wds-Button--${{
    sm: 'small',
    md: 'medium',
    lg: 'large'
  }[size]}`, `wds-Button--${priority}`, `wds-Button--${sentiment}`, className);
  const contentClassNames = clsx.clsx('wds-Button-content', {
    [`wds-Button-content--loading`]: loading
  });
  const content = /*#__PURE__*/jsxRuntime.jsxs(Body.default, {
    as: "span",
    type: size === 'sm' ? typography.Typography.BODY_DEFAULT_BOLD : typography.Typography.BODY_LARGE_BOLD,
    className: contentClassNames,
    children: [loading && /*#__PURE__*/jsxRuntime.jsx(ProcessIndicator.default, {
      size: size === 'sm' ? 'xxs' : 'xs',
      className: "wds-Button-loader",
      "data-testid": "button-loader-indicator"
    }), /*#__PURE__*/jsxRuntime.jsx("span", {
      className: "wds-Button-label",
      id: props.id ? `${props.id}_content` : undefined,
      "aria-hidden": loading,
      children: size === 'lg' ? /*#__PURE__*/jsxRuntime.jsx("span", {
        className: "wds-Button-labelText",
        children: children
      }) : /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
        children: [size === 'md' && addonStart?.type === 'avatar' && addonStart.value && /*#__PURE__*/jsxRuntime.jsx("span", {
          className: "wds-Button-avatars",
          children: /*#__PURE__*/jsxRuntime.jsx(AvatarLayout.default, {
            orientation: "horizontal",
            avatars: addonStart?.value,
            size: 24
          })
        }), addonStart?.type === 'icon' && addonStart.value && /*#__PURE__*/jsxRuntime.jsx("span", {
          className: `wds-Button-icon wds-Button-icon--${size} wds-Button-icon--start`,
          children: addonStart.value
        }), /*#__PURE__*/jsxRuntime.jsx("span", {
          className: "wds-Button-labelText",
          children: children
        }), addonEnd?.type === 'icon' && addonEnd?.value && /*#__PURE__*/jsxRuntime.jsx("span", {
          className: `wds-Button-icon wds-Button-icon--${size} wds-Button-icon--end`,
          children: addonEnd.value
        })]
      })
    })]
  });
  if (href && as !== 'button' || as === 'a') {
    return /*#__PURE__*/jsxRuntime.jsx(PrimitiveAnchor.default, {
      ref: ref,
      ...props,
      href: href,
      className: classNames,
      disabled: disabled || loading,
      "aria-busy": loading || undefined,
      type: undefined,
      children: content
    });
  }
  return /*#__PURE__*/jsxRuntime.jsx(PrimitiveButton.default, {
    ref: ref,
    ...props,
    className: classNames,
    disabled: disabled,
    loading: loading,
    type: type,
    href: undefined,
    target: undefined,
    children: content
  });
});

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