import { jsx as e, jsxs as c, Fragment as m } from "@emotion/react/jsx-runtime";
import { forwardRef as g, useId as z } from "react";
import { useModuleSkeleton as R } from "@m4l/core";
import { useComponentSize as x } from "../../../../hooks/useComponentSize/index.js";
import { getComponentSlotRoot as E } from "../../../../utils/getComponentSlotRoot.js";
import { SWITCH_CLASSES as L, SWITCH_KEY_COMPONENT as M } from "./constants.js";
import O from "clsx";
import { getOptionLabelColor as P } from "../../../../utils/getOptionLabelColor.js";
import { SwitchRootStyled as T, MUISwitchStyled as _, SkeletonStyled as S, LabelStyled as j } from "./slots/SwitchSlots.js";
const B = g(
  (p, u) => {
    const {
      className: b,
      size: h = "medium",
      disabled: t,
      color: f = "default",
      error: n,
      checked: r = !1,
      label: o,
      labelPlacement: i = "end",
      onChange: w,
      value: k,
      id: C,
      ...v
    } = p, { currentSize: s } = x(h), y = R(), I = E(M), N = z(), l = C || N, a = {
      disabled: t,
      color: f,
      error: n,
      size: s,
      checked: r
    }, d = o ? /* @__PURE__ */ e(
      j,
      {
        id: `${l}-label`,
        component: "label",
        htmlFor: l,
        variant: "body",
        color: P(r, t),
        ownerState: { ...a },
        size: s,
        disabled: t,
        ellipsis: !0,
        children: o
      }
    ) : null;
    return /* @__PURE__ */ e(
      T,
      {
        ownerState: { ...a },
        className: O(b, I),
        children: y ? /* @__PURE__ */ c(m, { children: [
          /* @__PURE__ */ e(S, { "data-testid": "switch-skeleton", variant: "rounded", className: L.skeleton }),
          o && /* @__PURE__ */ e(S, { "data-testid": "switch-skeleton-label", variant: "rectangular", className: "switchSkeletonLabel" })
        ] }) : /* @__PURE__ */ c(m, { children: [
          i === "start" && d,
          /* @__PURE__ */ e(
            _,
            {
              ref: u,
              id: l,
              ownerState: { ...a },
              disableRipple: !0,
              checked: r,
              disabled: t,
              inputProps: {
                "aria-invalid": n ? "true" : void 0,
                ...o && { "aria-labelledby": `${l}-label` }
              },
              value: k,
              onChange: w,
              ...v
            }
          ),
          i === "end" && d
        ] })
      }
    );
  }
);
export {
  B as Switch
};
