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); }
import React from "react";
import Spinner from "../../atoms/spinner/spinner";
import Pressable from "../../atoms/pressable/pressable";
import { useMolecularComponentConfig } from "../../../hooks/useMolecularComponentConfig";
import { boxStyleFunctions } from "../../../theme/src/style-functions";
import { useButtonGroup } from "../button/button-group";
/** IconButton is a specialized Button which renders an icon within. It can be used to trigger an action or event, such as submitting a form, opening a dialog, canceling an action, or performing a delete operation */
const IconButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(({
  icon,
  isLoading = false,
  isFullWidth = false,
  ...rest
}, ref) => {
  const {
    size,
    variant,
    isDisabled,
    colorScheme
  } = useButtonGroup();

  // Overwrite props from button group
  rest.size = rest.size ?? size;
  rest.variant = rest.variant ?? variant;
  rest.isDisabled = rest.isDisabled ?? isDisabled;
  rest.colorScheme = rest.colorScheme ?? colorScheme;
  const molecularProps = useMolecularComponentConfig("IconButton", rest, {
    size: rest.size,
    variant: rest.variant
  }, rest.colorScheme, boxStyleFunctions, "pressable", "pressable", "pressable");
  const {
    atoms
  } = molecularProps;

  // Determine if the button is disabled
  const isButtonDisabled = rest.isDisabled ? true : isLoading;
  return /*#__PURE__*/React.createElement(Pressable, _extends({}, atoms.pressable, {
    ref: ref,
    isDisabled: isButtonDisabled,
    alignSelf: isFullWidth ? "stretch" : "flex-start",
    accessibilityLabel: !isLoading ? atoms.pressable.accessibilityLabel : "Loading",
    accessibilityState: {
      disabled: isButtonDisabled,
      busy: isLoading
    }
  }), isLoading ? /*#__PURE__*/React.createElement(Spinner, atoms.spinner) : ( /*#__PURE__*/React.cloneElement(icon, atoms.icon)));
}));
IconButton.displayName = "IconButton";
export default IconButton;
//# sourceMappingURL=icon-button.js.map