"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireDefault(require("react"));
var _spinner = _interopRequireDefault(require("../../atoms/spinner/spinner"));
var _pressable = _interopRequireDefault(require("../../atoms/pressable/pressable"));
var _useMolecularComponentConfig = require("../../../hooks/useMolecularComponentConfig");
var _styleFunctions = require("../../../theme/src/style-functions");
var _buttonGroup = require("../button/button-group");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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); }
/** 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.default.memo( /*#__PURE__*/_react.default.forwardRef(({
  icon,
  isLoading = false,
  isFullWidth = false,
  ...rest
}, ref) => {
  const {
    size,
    variant,
    isDisabled,
    colorScheme
  } = (0, _buttonGroup.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 = (0, _useMolecularComponentConfig.useMolecularComponentConfig)("IconButton", rest, {
    size: rest.size,
    variant: rest.variant
  }, rest.colorScheme, _styleFunctions.boxStyleFunctions, "pressable", "pressable", "pressable");
  const {
    atoms
  } = molecularProps;

  // Determine if the button is disabled
  const isButtonDisabled = rest.isDisabled ? true : isLoading;
  return /*#__PURE__*/_react.default.createElement(_pressable.default, _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.default.createElement(_spinner.default, atoms.spinner) : ( /*#__PURE__*/_react.default.cloneElement(icon, atoms.icon)));
}));
IconButton.displayName = "IconButton";
var _default = exports.default = IconButton;
//# sourceMappingURL=icon-button.js.map