import { jsx as e, jsxs as H, Fragment as I } from "@emotion/react/jsx-runtime";
import { forwardRef as j, useId as d } from "react";
import { useFormContext as T, Controller as M } from "react-hook-form";
import { useComponentSize as B } from "../../../hooks/useComponentSize/index.js";
import { RHFCheckboxRoot as E, LabelComponent as L, ContainerCheckTypography as O, CheckBoxStyled as q } from "./slots/RHFCheckBoxSlots.js";
import { HelperError as v } from "../../HelperError/HelperError.js";
const Q = j(function(c, f) {
  const {
    name: r,
    size: p = "medium",
    label: s,
    disabled: a = !1,
    mandatory: h,
    id: u,
    mandatoryMessage: S,
    helperMessage: C,
    inlineText: x,
    helperText: b
  } = c, {
    control: z,
    formState: { errors: F }
  } = T(), { currentSize: n } = B(p), t = n === "small" || n === "medium" ? n : "medium", l = {
    disabled: a,
    error: !!F[r],
    name: r,
    size: t,
    paletteColor: "default"
  }, m = l, i = d(), g = d(), k = u || g;
  return /* @__PURE__ */ e(E, { ownerState: m, children: /* @__PURE__ */ e(
    M,
    {
      name: r,
      control: z,
      render: ({ field: { onChange: w, value: y }, fieldState: { error: o }, formState: { isSubmitting: R } }) => /* @__PURE__ */ H(I, { children: [
        s && /* @__PURE__ */ e(
          L,
          {
            ownerState: { ...m },
            size: t,
            label: s || "",
            mandatory: h,
            mandatoryMessage: S,
            helperMessage: C,
            helperText: b
          }
        ),
        /* @__PURE__ */ e(O, { children: /* @__PURE__ */ e(
          q,
          {
            ownerState: { ownerState: l, error: !!o },
            size: t,
            onChange: w,
            checked: y,
            disabled: a || R,
            disableRipple: !0,
            inlineText: x,
            htmlFor: k,
            error: !!o,
            id: i,
            ref: f
          }
        ) }),
        o?.message && /* @__PURE__ */ e(v, { htmlFor: i, size: t, message: o?.message + "" })
      ] })
    }
  ) });
});
export {
  Q as RHFCheckbox
};
