import { jsx as e, jsxs as _, Fragment as z } from "@emotion/react/jsx-runtime";
import { useFormContext as E, Controller as H } from "react-hook-form";
import M from "@mui/material/utils/useId";
import { getPropDataTestId as y } from "../../../test/getNameDataTestId.js";
import { useComponentSize as L } from "../../../hooks/useComponentSize/index.js";
import { Label as P } from "../../Label/Label.js";
import { HelperError as T } from "../../HelperError/HelperError.js";
import { NumberInput as j } from "../../NumberInput/NumberInput.js";
import { RHFNumberInputSlots as v } from "./slots/RHFNumberInputEnum.js";
import { RHF_NUMBER_INPUT_KEY_COMPONENT as w } from "./constants.js";
import { RootStyled as A } from "./slots/RHFNumberInputSlots.js";
const X = (n) => {
  const {
    name: s,
    max: a,
    min: i,
    step: l,
    disabled: d,
    size: o = "medium",
    variant: p = "outlined",
    label: m,
    mandatory: c,
    mandatoryMessage: f,
    helperMessage: u,
    startAdornment: g,
    endAdornment: h,
    ...S
  } = n, { control: F } = E(), { currentSize: b } = L(o), C = {
    iconSize: b
  }, t = M();
  return /* @__PURE__ */ e(
    A,
    {
      ownerState: { ...C },
      ...y(w, v.root),
      children: /* @__PURE__ */ e(
        H,
        {
          name: s,
          control: F,
          render: ({ field: { value: I, onChange: N }, fieldState: { error: r }, formState: { isSubmitting: x } }) => /* @__PURE__ */ _(z, { children: [
            m && /* @__PURE__ */ e(
              P,
              {
                htmlFor: t,
                label: m,
                mandatory: c,
                mandatoryMessage: f,
                helperMessage: u,
                size: o
              }
            ),
            /* @__PURE__ */ e(
              j,
              {
                id: t,
                size: o,
                step: l,
                max: a,
                min: i,
                value: I,
                onChange: (U, R) => {
                  N(R);
                },
                variant: p,
                disabled: d || x,
                startAdornment: g,
                endAdornment: h,
                error: !!r,
                ...S
              }
            ),
            r?.message && /* @__PURE__ */ e(T, { htmlFor: t, size: o, message: r.message })
          ] })
        }
      )
    }
  );
};
export {
  X as RHFNumberInput
};
