"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.buttonVariantValues = exports.buttonTypeValues = exports.buttonSizeValues = exports.BaseButton = void 0;
var _Button2 = _interopRequireDefault(require("@mui/material/Button"));
var _react = require("react");
var _MuiPropsContext = require("../MuiPropsContext.cjs");
var _Tooltip = require("../Tooltip.cjs");
var _ButtonContext = require("./ButtonContext.cjs");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/*!
 * Copyright (c) 2022-present, Okta, Inc. and/or its affiliates. All rights reserved.
 * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
 *
 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *
 * See the License for the specific language governing permissions and limitations under the License.
 */

const buttonSizeValues = exports.buttonSizeValues = ["small", "medium", "large"];
const buttonTypeValues = exports.buttonTypeValues = ["button", "submit", "reset"];
const buttonVariantValues = exports.buttonVariantValues = ["primary", "secondary", "danger", "dangerSecondary", "floating", "floatingAction"];
const BaseButton = ({
  ariaControls,
  ariaDescribedBy,
  ariaExpanded,
  ariaHasPopup,
  ariaLabel,
  ariaLabelledBy,
  buttonRef,
  children,
  endIcon,
  href,
  id,
  isDisabled,
  isFullWidth: isFullWidthProp,
  label = "",
  onClick,
  size = "medium",
  startIcon,
  tabIndex,
  testId,
  tooltipText,
  translate,
  type = "button",
  variant: variantProp
}) => {
  const muiProps = (0, _MuiPropsContext.useMuiProps)();
  const variant = variantProp === "tertiary" ? "secondary" : variantProp;
  const localButtonRef = (0, _react.useRef)(null);
  const buttonContext = (0, _ButtonContext.useButton)();
  const isFullWidth = (0, _react.useMemo)(() => buttonContext.isFullWidth ? buttonContext.isFullWidth : isFullWidthProp, [buttonContext, isFullWidthProp]);
  (0, _react.useImperativeHandle)(buttonRef, () => ({
    focus: () => {
      localButtonRef.current?.focus();
    }
  }), []);
  const renderButton = (0, _react.useCallback)(muiProps => {
    return (0, _jsxRuntime.jsx)(_Button2.default, {
      ...muiProps,
      "aria-controls": ariaControls,
      "aria-describedby": ariaDescribedBy,
      "aria-expanded": ariaExpanded,
      "aria-haspopup": ariaHasPopup,
      "aria-label": ariaLabel,
      "aria-labelledby": ariaLabelledBy,
      "data-se": testId,
      disabled: isDisabled,
      endIcon: endIcon,
      fullWidth: isFullWidth,
      href: href,
      id: id,
      onClick: onClick,
      ref: element => {
        if (element) {
          localButtonRef.current = element;
          muiProps?.ref?.(element);
        }
      },
      size: size,
      startIcon: startIcon,
      tabIndex: tabIndex,
      translate: translate,
      type: type,
      variant: variant,
      children: children ?? label
    });
  }, [ariaControls, ariaDescribedBy, ariaExpanded, ariaHasPopup, ariaLabel, ariaLabelledBy, endIcon, href, id, isDisabled, isFullWidth, label, children, onClick, size, startIcon, tabIndex, testId, translate, type, variant]);
  if (tooltipText) {
    return (0, _jsxRuntime.jsx)(_Tooltip.Tooltip, {
      ariaType: "description",
      placement: "top",
      text: tooltipText,
      children: (0, _jsxRuntime.jsx)(_MuiPropsContext.MuiPropsContext.Consumer, {
        children: renderButton
      })
    });
  }
  return renderButton(muiProps);
};
const MemoizedBaseButton = exports.BaseButton = (0, _react.memo)(BaseButton);
MemoizedBaseButton.displayName = "BaseButton";
//# sourceMappingURL=BaseButton.cjs.map