import { forwardRef } from 'react';
import PrimitiveButton from '../primitives/PrimitiveButton/PrimitiveButton.mjs';
import PrimitiveAnchor from '../primitives/PrimitiveAnchor/PrimitiveAnchor.mjs';
import AvatarLayout from '../avatarLayout/AvatarLayout.mjs';
import ProcessIndicator from '../processIndicator/ProcessIndicator.mjs';
import { clsx } from 'clsx';
import '../common/theme.mjs';
import '../common/direction.mjs';
import '@transferwise/neptune-tokens';
import '../common/propsValues/control.mjs';
import '../common/propsValues/size.mjs';
import { Typography } from '../common/propsValues/typography.mjs';
import '../common/propsValues/width.mjs';
import '../common/propsValues/type.mjs';
import '../common/propsValues/dateMode.mjs';
import '../common/propsValues/monthFormat.mjs';
import '../common/propsValues/position.mjs';
import '../common/propsValues/layouts.mjs';
import '../common/propsValues/status.mjs';
import '../common/propsValues/sentiment.mjs';
import '../common/propsValues/profileType.mjs';
import '../common/propsValues/variant.mjs';
import '../common/propsValues/scroll.mjs';
import '../common/propsValues/markdownNodeType.mjs';
import '../common/fileType.mjs';
import '@transferwise/formatting';
import '@transferwise/icons';
import 'react-intl';
import '../common/closeButton/CloseButton.messages.mjs';
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
import Body from '../body/Body.mjs';

/* eslint-disable react/display-name */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
const Button = /*#__PURE__*/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('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('wds-Button-content', {
    [`wds-Button-content--loading`]: loading
  });
  const content = /*#__PURE__*/jsxs(Body, {
    as: "span",
    type: size === 'sm' ? Typography.BODY_DEFAULT_BOLD : Typography.BODY_LARGE_BOLD,
    className: contentClassNames,
    children: [loading && /*#__PURE__*/jsx(ProcessIndicator, {
      size: size === 'sm' ? 'xxs' : 'xs',
      className: "wds-Button-loader",
      "data-testid": "button-loader-indicator"
    }), /*#__PURE__*/jsx("span", {
      className: "wds-Button-label",
      id: props.id ? `${props.id}_content` : undefined,
      "aria-hidden": loading,
      children: size === 'lg' ? /*#__PURE__*/jsx("span", {
        className: "wds-Button-labelText",
        children: children
      }) : /*#__PURE__*/jsxs(Fragment, {
        children: [size === 'md' && addonStart?.type === 'avatar' && addonStart.value && /*#__PURE__*/jsx("span", {
          className: "wds-Button-avatars",
          children: /*#__PURE__*/jsx(AvatarLayout, {
            orientation: "horizontal",
            avatars: addonStart?.value,
            size: 24
          })
        }), addonStart?.type === 'icon' && addonStart.value && /*#__PURE__*/jsx("span", {
          className: `wds-Button-icon wds-Button-icon--${size} wds-Button-icon--start`,
          children: addonStart.value
        }), /*#__PURE__*/jsx("span", {
          className: "wds-Button-labelText",
          children: children
        }), addonEnd?.type === 'icon' && addonEnd?.value && /*#__PURE__*/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__*/jsx(PrimitiveAnchor, {
      ref: ref,
      ...props,
      href: href,
      className: classNames,
      disabled: disabled || loading,
      "aria-busy": loading || undefined,
      type: undefined,
      children: content
    });
  }
  return /*#__PURE__*/jsx(PrimitiveButton, {
    ref: ref,
    ...props,
    className: classNames,
    disabled: disabled,
    loading: loading,
    type: type,
    href: undefined,
    target: undefined,
    children: content
  });
});

export { Button as default };
//# sourceMappingURL=Button.mjs.map
