var _excluded = ["children", "className", "isDisabled", "isLoading", "icon", "iconPosition", "onClick", "size", "title", "type", "variant"];
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; }
import { IconLoader } from '@defencedigital/icon-library';
import React from 'react';
import { BUTTON_ICON_POSITION, BUTTON_VARIANT } from './constants';
import { StyledButton } from './partials/StyledButton';
import { StyledIconWrapper } from './partials/StyledIconWrapper';
import { StyledText } from './partials/StyledText';
import { StyledIconLoaderWrapper } from './partials/StyledIconLoader';
import { COMPONENT_SIZE } from '../Forms';
export var Button = function Button(_ref) {
  var children = _ref.children,
    className = _ref.className,
    isDisabled = _ref.isDisabled,
    _ref$isLoading = _ref.isLoading,
    isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
    icon = _ref.icon,
    _ref$iconPosition = _ref.iconPosition,
    iconPosition = _ref$iconPosition === void 0 ? BUTTON_ICON_POSITION.RIGHT : _ref$iconPosition,
    onClick = _ref.onClick,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? COMPONENT_SIZE.FORMS : _ref$size,
    title = _ref.title,
    _ref$type = _ref.type,
    type = _ref$type === void 0 ? 'button' : _ref$type,
    _ref$variant = _ref.variant,
    variant = _ref$variant === void 0 ? BUTTON_VARIANT.PRIMARY : _ref$variant,
    rest = _objectWithoutProperties(_ref, _excluded);
  return /*#__PURE__*/React.createElement(StyledButton, _extends({
    className: className,
    $variant: variant,
    $size: size,
    $iconPosition: iconPosition,
    disabled: isDisabled || isLoading,
    type: type,
    "aria-label": children,
    title: title,
    onClick: onClick
  }, rest), isLoading && /*#__PURE__*/React.createElement(StyledIconLoaderWrapper, {
    "aria-hidden": true
  }, /*#__PURE__*/React.createElement(IconLoader, {
    size: size === COMPONENT_SIZE.FORMS ? 26 : 21
  })), /*#__PURE__*/React.createElement(StyledText, {
    $isLoading: isLoading
  }, children), icon && /*#__PURE__*/React.createElement(StyledIconWrapper, {
    $buttonHasText: Boolean(children),
    $buttonSize: size,
    $iconPosition: iconPosition,
    $isLoading: isLoading,
    "aria-hidden": true
  }, icon));
};
Button.displayName = 'Button';