"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFormFieldProps = void 0;
const react_1 = require("react");
const react_hook_form_1 = require("react-hook-form");
const useForwardedRef_1 = require("../../components/useForwardedRef");
const FormControlProvider_1 = require("../FormControlProvider");
const useFormFieldErrorProps_1 = require("../useFormFieldErrorProps");
const useFormInputProps_1 = require("../useFormInputProps");
/**
 * хук предназначен для получения пропсов при инициализации нового поля в RHF
 */
const useFormFieldProps = (props) => {
    const { field, fieldState } = (0, react_hook_form_1.useController)({
        ...props,
        disabled: undefined,
    });
    const ref = (0, useForwardedRef_1.useForwardedRef)(field.ref);
    const contextProps = (0, react_1.useContext)(FormControlProvider_1.FormControlContext);
    const inputProps = (0, useFormInputProps_1.useFormInputProps)(props);
    const errorProps = (0, useFormFieldErrorProps_1.useFormFieldErrorProps)(fieldState);
    return {
        ...contextProps,
        ...field,
        ...inputProps,
        ...errorProps,
        inputRef: ref,
    };
};
exports.useFormFieldProps = useFormFieldProps;
