"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const jsxRuntime = require("react/jsx-runtime");
const errorMessage = require("@hookform/error-message");
const reactHookForm = require("react-hook-form");
;/* empty css                                                                                                                                                                                        */
;/* empty css                                                                                                                                                                                         */
;/* empty css                                                                                                                                                                                                 */
;/* empty css                                                                                                                                                                                            */
;/* empty css                                                                                                                                                                                            */
const TextInput = require("../../primitive/TextInput/TextInput.cjs");
const FormTextInput = ({ name, rules, onChange, ...rest }) => {
  const { control, formState, getFieldState } = reactHookForm.useFormContext();
  const { error } = getFieldState(name, formState);
  return /* @__PURE__ */ jsxRuntime.jsx(
    reactHookForm.Controller,
    {
      control,
      name,
      rules,
      render: ({ field }) => {
        const { value = "", onChange: handleChange, ...restField } = field;
        return /* @__PURE__ */ jsxRuntime.jsx(
          TextInput.TextInput,
          {
            value,
            onChange: (e) => {
              handleChange(e);
              onChange == null ? void 0 : onChange(e);
            },
            error: error ? /* @__PURE__ */ jsxRuntime.jsx(errorMessage.ErrorMessage, { errors: formState.errors, name }) : void 0,
            ...restField,
            ...rest
          }
        );
      }
    }
  );
};
exports.FormTextInput = FormTextInput;
