import { jsx as o } from "@emotion/react/jsx-runtime";
import { useModuleSkeleton as O } from "@m4l/core";
import x from "clsx";
import P, { forwardRef as V, useMemo as b } from "react";
import { useComponentSize as _ } from "../../../../hooks/useComponentSize/index.js";
import { Tooltip as L } from "@m4l/base";
import { ICON_BUTTON_CLASSES as r } from "./constants.js";
import { evalIconColor as q } from "./helpers/evalIconColor.js";
import { IconStyled as M, SkeletonStyled as D, BadgeStyled as F, StyledMUIIconButton as N } from "./slots/IconButtonSlots.js";
const tt = V((T, C) => {
  const {
    tooltip: a,
    placement: U = "bottom",
    size: g = "medium",
    variant: i = "text",
    disabled: t,
    onClick: y,
    color: l = "default",
    selected: c = !1,
    icon: B,
    src: h,
    rotationAngle: m,
    className: R,
    badgeProps: w = {},
    dataTestId: s,
    ...v
  } = T, { currentSize: u } = _(g), d = u === "small" || u === "medium" ? u : "medium", p = O(), e = b(() => ({
    variant: i,
    size: d,
    disabled: t,
    color: l,
    selected: c,
    isSkeleton: p
  }), [i, d, t, l, c, p]), f = b(
    () => q(l, i),
    [l, i]
  ), { variant: I, color: j, invisible: A, badgeContent: z = "", ...E } = w, k = b(() => (n) => !n || typeof n == "boolean" || typeof n == "number" ? null : typeof n == "string" ? /* @__PURE__ */ o(
    M,
    {
      ownerState: e,
      src: n,
      size: d,
      color: f,
      disabled: t,
      rotationAngle: m,
      "data-testid": s ?? "IconButtonRoot"
    }
  ) : P.isValidElement(n) ? /* @__PURE__ */ o(
    M,
    {
      ownerState: e,
      src: n,
      size: d,
      color: f,
      disabled: t,
      rotationAngle: m,
      "data-testid": s ?? "IconButtonRoot"
    }
  ) : null, [e, d, f, t, m, s]);
  if (p)
    return /* @__PURE__ */ o(D, { ownerState: { ...e } });
  const S = I || z ? /* @__PURE__ */ o(
    F,
    {
      ownerState: e,
      badgeContent: I === "dot" ? "" : z,
      invisible: A,
      variant: I,
      color: j,
      ...E,
      children: /* @__PURE__ */ o(
        N,
        {
          ref: C,
          ownerState: e,
          onClick: t ? void 0 : y,
          disableRipple: !0,
          disabled: t,
          "data-testid": s ?? "IconButtonRoot",
          color: l,
          role: "button",
          ...v,
          className: x(
            r[i],
            r.styledMUIIconButton,
            c && r.selected,
            R
          ),
          children: k(B || h)
        }
      )
    }
  ) : /* @__PURE__ */ o(
    N,
    {
      ref: C,
      ownerState: e,
      onClick: t ? void 0 : y,
      disableRipple: !0,
      disabled: t,
      "data-testid": s ?? "IconButtonRoot",
      color: l,
      ...v,
      className: x(
        r[i],
        r.styledMUIIconButton,
        c && r.selected,
        R
      ),
      children: k(B || h)
    }
  );
  return a ? /* @__PURE__ */ o(L, { title: a, placement: U, children: a && t ? /* @__PURE__ */ o("span", { style: { display: "inline-flex" }, children: S }) : S }) : S;
});
export {
  tt as IconButton
};
