import { jsx } from "react/jsx-runtime";
import { ErrorMessage } from "@hookform/error-message";
import { useFormContext, Controller } from "react-hook-form";
/* empty css                                                                                                                                                                                       */
/* empty css                                                                                                                                                                                        */
/* empty css                                                                                                                                                                                                */
/* empty css                                                                                                                                                                                           */
/* empty css                                                                                                                                                                                           */
import { NumberInput } from "../../primitive/NumberInput/index.mjs";
const FormNumberInput = ({ name, rules, onChange, ...rest }) => {
  const { control, formState, getFieldState } = useFormContext();
  const { error } = getFieldState(name, formState);
  return /* @__PURE__ */ jsx(
    Controller,
    {
      control,
      name,
      rules,
      render: ({ field }) => {
        const { onChange: handleChange, ...restField } = field;
        return /* @__PURE__ */ jsx(
          NumberInput,
          {
            ...rest,
            onChange: (value) => {
              handleChange(value);
              onChange == null ? void 0 : onChange(value);
            },
            ...restField,
            error: error ? /* @__PURE__ */ jsx(ErrorMessage, { errors: formState.errors, name }) : void 0
          }
        );
      }
    }
  );
};
export {
  FormNumberInput
};
