import { Controller } from "react-hook-form";
import { NumericalInput } from "../NumericalInput.mjs";
import { useFormContext } from "./context.mjs";
import { jsx } from "react/jsx-runtime";
function FormNumericalInput({
  id,
  helperText,
  error: defaultError,
  ...props
}) {
  const {
      control,
      formState: {
        errors
      },
      disabled
    } = useFormContext(),
    error = !!errors[id] || defaultError,
    supportingText = errors?.[id]?.message || helperText;
  return /* @__PURE__ */jsx(Controller, {
    control,
    name: id,
    render: ({
      field
    }) => /* @__PURE__ */jsx(NumericalInput, {
      ...props,
      fg: 1,
      disabled: disabled || props?.disabled,
      onChangeText: e => {
        const newValue = e?.replace(/[^0-9.]/g, "").replace(/(\..*)\./g, "$1");
        field?.onChange(newValue);
      },
      value: field?.value?.toString(),
      onValueChange: v => field?.onChange(v),
      onBlur: field?.onBlur,
      id,
      error,
      supportingText
    })
  });
}
export { FormNumericalInput };
//# sourceMappingURL=FormNumericalInput.mjs.map
