import { jsx, jsxs } from "react/jsx-runtime";
import { forwardRef, useMemo } from "react";
/* empty css                   */
import Button$1 from "../../node_modules/@mui/material/Button/Button.js";
const Button = forwardRef(
  ({
    children,
    size = "large",
    variant = "contained",
    loading = false,
    icon,
    iconPlacement = "left",
    disabled,
    className = "",
    type = "default",
    "aria-label": ariaLabel,
    ...args
  }, ref) => {
    const convertedVariant = useMemo(() => {
      switch (variant) {
        case "secondary":
        case "outlined":
          return "outlined";
        case "tertiary":
          return "tertiary";
        case "text":
          return "text";
        case "url":
          return "link";
        case "primary":
        case "contained":
        default:
          return "contained";
      }
    }, [variant]);
    const classStr = useMemo(() => {
      let retVal = `ia-styles ia-btn ${type === "destructive" ? "ia-btn-destructive" : ""} ${className}`;
      switch (convertedVariant) {
        case "outlined":
          retVal += " ia-btn-outlined";
          break;
        case "link":
          retVal += " ia-btn-link";
          break;
        case "text":
          retVal += " ia-btn-text";
          break;
        case "tertiary":
          retVal += " ia-btn-tertiary";
          break;
        case "contained":
        default:
          retVal += " ia-btn-contained";
          break;
      }
      switch (size) {
        case "small":
          retVal += " ia-btn-small";
          break;
        case "medium":
          retVal += " ia-btn-medium";
          break;
        case "large":
        default:
          retVal += " ia-btn-large";
          break;
      }
      if (disabled) {
        retVal += " ia-btn-disabled";
      }
      if (icon) {
        if (children) {
          retVal += " ia-btn-with-icon";
        } else {
          retVal += " ia-btn-only-icon";
        }
      }
      return retVal;
    }, [children, convertedVariant, size, disabled, icon, type, className]);
    const finalLabel = useMemo(() => {
      if (variant === "url" && !disabled && loading && children) {
        return "Loading...";
      }
      return children;
    }, [variant, disabled, loading, children]);
    const finalIcon = useMemo(() => {
      if (!icon && !loading) {
        return null;
      }
      return /* @__PURE__ */ jsx("div", { className: `ia-btn-icon ${loading ? "ia-btn-icon-loading" : ""}`, children: loading && (convertedVariant !== "link" || !children) ? /* @__PURE__ */ jsx("div", { "aria-hidden": "true", className: "ia-btn-loading-icon", children: /* @__PURE__ */ jsx(
        "span",
        {
          className: `ia-btn-loading-track ia-btn-loading-${convertedVariant === "contained" ? "dark" : "light"}`
        }
      ) }) : icon });
    }, [icon, loading, convertedVariant, children]);
    const computedAriaLabel = ariaLabel ?? (typeof children === "string" ? void 0 : "Button");
    const isDisabled = disabled ?? loading;
    const commonProps = {
      ref,
      disabled: isDisabled,
      className: classStr,
      disableRipple: true,
      disableElevation: true,
      "aria-label": computedAriaLabel,
      "aria-busy": loading,
      "aria-disabled": isDisabled,
      ...args
    };
    if (iconPlacement === "right") {
      return /* @__PURE__ */ jsxs(Button$1, { ...commonProps, children: [
        finalLabel,
        finalIcon
      ] });
    }
    return /* @__PURE__ */ jsxs(Button$1, { ...commonProps, children: [
      finalIcon,
      finalLabel
    ] });
  }
);
Button.displayName = "Button";
export {
  Button
};
