import _Button from "@mui/material/Button";
/*!
 * 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.
 */
import { memo, useCallback, useImperativeHandle, useMemo, useRef } from "react";
import { MuiPropsContext, useMuiProps } from "../MuiPropsContext.js";
import { Tooltip } from "../Tooltip.js";
import { useButton } from "./ButtonContext.js";
import { jsx as _jsx } from "react/jsx-runtime";
export const buttonSizeValues = ["small", "medium", "large"];
export const buttonTypeValues = ["button", "submit", "reset"];
export const 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 = useMuiProps();
  const variant = variantProp === "tertiary" ? "secondary" : variantProp;
  const localButtonRef = useRef(null);
  const buttonContext = useButton();
  const isFullWidth = useMemo(() => buttonContext.isFullWidth ? buttonContext.isFullWidth : isFullWidthProp, [buttonContext, isFullWidthProp]);
  useImperativeHandle(buttonRef, () => ({
    focus: () => {
      localButtonRef.current?.focus();
    }
  }), []);
  const renderButton = useCallback(muiProps => {
    return _jsx(_Button, {
      ...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 _jsx(Tooltip, {
      ariaType: "description",
      placement: "top",
      text: tooltipText,
      children: _jsx(MuiPropsContext.Consumer, {
        children: renderButton
      })
    });
  }
  return renderButton(muiProps);
};
const MemoizedBaseButton = memo(BaseButton);
MemoizedBaseButton.displayName = "BaseButton";
export { MemoizedBaseButton as BaseButton };
//# sourceMappingURL=BaseButton.js.map