import { jsx as o, jsxs as w, Fragment as N } from "@emotion/react/jsx-runtime";
import { clsx as m } from "clsx";
import { useRef as L, cloneElement as R, isValidElement 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 y } from "../../../../helpers/isImageComponentElement/isImageComponentElement.js";
function z(e, s, n) {
  return e == null ? e : typeof e == "string" && n ? /* @__PURE__ */ o(
    q,
    {
      ownerState: { ...n.ownerState },
      className: n.iconClassName,
      src: e,
      size: n.size
    }
  ) : j(e) ? R(e, { selected: s }) : e;
}
function ne(e) {
  const {
    size: s,
    disabled: n,
    label: r,
    description: c,
    urlIcon: A,
    value: C,
    color: E = "default",
    variant: g = "outlined",
    className: d,
    ariaLabel: x,
    startAdornment: I,
    endAdornment: u,
    ...D
  } = e, b = L(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
  }, l = B(W, O), h = {
    ownerState: t,
    iconClassName: m(l.icon, d),
    size: s
  }, a = z(
    I ?? A,
    v,
    h
  ), i = z(
    u,
    v,
    h
  ), T = r != null || u != null;
  return /* @__PURE__ */ o(
    G,
    {
      ref: b,
      "aria-label": x,
      label: T ? /* @__PURE__ */ w(N, { children: [
        /* @__PURE__ */ w(_, { className: l.labelGroup, ownerState: { ...t }, children: [
          r != null ? /* @__PURE__ */ o(F, { size: p, variant: t.hasDescription ? "captionDens" : "bodyStandard", className: m(l.title, d), ownerState: { ...t }, children: r }) : null,
          c != null ? /* @__PURE__ */ o(K, { color: "text.secondary", size: p, className: m(l.description, d), ownerState: { ...t }, variant: "bodyStandard", children: c }) : null
        ] }),
        i != null && y(i) ? /* @__PURE__ */ o(Y, { ownerState: { ...t }, children: i }) : i
      ] }) : void 0,
      disabled: f || n,
      ownerState: { ...t },
      icon: a != null ? y(a) ? /* @__PURE__ */ o(V, { ownerState: { ...t }, children: a }) : /* @__PURE__ */ o(N, { children: a }) : void 0,
      value: C,
      tabIndex: 0,
      disableRipple: !0,
      className: m(l.root, d),
      ...D
    }
  );
}
export {
  ne as Tab
};
