import { jsx as r, jsxs as w, Fragment as L } from "@emotion/react/jsx-runtime";
import { clsx as m } from "clsx";
import { useRef as R, isValidElement as z, cloneElement as j } from "react";
import { useModuleSkeleton as k } from "@m4l/core";
import { useComponentSize as M } from "../../../../hooks/useComponentSize/index.js";
import { TabSlots as O } from "./Slots/TabEnum.js";
import { TAB_KEY_COMPONENT as W } from "./constants.js";
import { getComponentClasses as B } from "../../../../utils/getComponentSlotRoot.js";
import { RootStyled as G, StartAdornmentImageWrapperStyled as V, LabelGroupStyled as _, TitleStyled as F, DescriptionStyled as K, EndAdornmentImageWrapperStyled as Y, IconStyled as q } from "./Slots/TabSlots.js";
import { isImageComponentElement as N } from "../../../../helpers/isImageComponentElement/isImageComponentElement.js";
function y(e, s, n) {
  return e == null ? e : typeof e == "string" && n ? /* @__PURE__ */ r(
    q,
    {
      ownerState: { ...n.ownerState },
      className: n.iconClassName,
      src: e,
      size: n.size
    }
  ) : z(e) ? j(e, { selected: s }) : e;
}
function ne(e) {
  const {
    size: s,
    disabled: n,
    label: l,
    description: c,
    urlIcon: A,
    value: C,
    color: E = "default",
    variant: g = "outlined",
    className: d,
    ariaLabel: x,
    startAdornment: I,
    endAdornment: u,
    ...D
  } = e, b = R(null), { currentSize: S } = M(s), p = S === "small" || S === "medium" ? S : "medium", f = k(), v = b.current?.classList.contains("Mui-selected") ?? !1, t = {
    tabColor: E,
    tabSize: p,
    tabDisabled: n,
    tabSkeleton: f,
    tabVariant: g,
    hasDescription: !!c
  }, a = B(W, O), h = {
    ownerState: t,
    iconClassName: m(a.icon, d),
    size: s
  }, o = y(
    I ?? A,
    v,
    h
  ), i = y(
    u,
    v,
    h
  ), T = l != null || u != null;
  return /* @__PURE__ */ r(
    G,
    {
      ref: b,
      "aria-label": x,
      label: T ? /* @__PURE__ */ w(L, { children: [
        /* @__PURE__ */ w(_, { className: a.labelGroup, ownerState: { ...t }, children: [
          l != null ? /* @__PURE__ */ r(F, { size: p, variant: t.hasDescription ? "captionDens" : "bodyStandard", className: m(a.title, d), ownerState: { ...t }, children: l }) : null,
          c != null ? /* @__PURE__ */ r(K, { color: "text.secondary", size: p, className: m(a.description, d), ownerState: { ...t }, variant: "bodyStandard", children: c }) : null
        ] }),
        i != null && N(i) ? /* @__PURE__ */ r(Y, { ownerState: { ...t }, children: i }) : i
      ] }) : void 0,
      disabled: f || n,
      ownerState: { ...t },
      icon: o != null ? N(o) ? /* @__PURE__ */ r(V, { ownerState: { ...t }, children: o }) : z(o) ? o : /* @__PURE__ */ r("span", { children: o }) : void 0,
      value: C,
      tabIndex: 0,
      disableRipple: !0,
      className: m(a.root, d),
      ...D
    }
  );
}
export {
  ne as Tab
};
