import { useContext } from 'react';
import { useController, } from 'react-hook-form';
import { useForwardedRef } from '../../components/useForwardedRef';
import { FormControlContext } from '../FormControlProvider';
import { useFormFieldErrorProps, } from '../useFormFieldErrorProps';
import { useFormInputProps, } from '../useFormInputProps';
/**
 * хук предназначен для получения пропсов при инициализации нового поля в RHF
 */
export const useFormFieldProps = (props) => {
    const { field, fieldState } = useController({
        ...props,
        disabled: undefined,
    });
    const ref = useForwardedRef(field.ref);
    const contextProps = useContext(FormControlContext);
    const inputProps = useFormInputProps(props);
    const errorProps = useFormFieldErrorProps(fieldState);
    return {
        ...contextProps,
        ...field,
        ...inputProps,
        ...errorProps,
        inputRef: ref,
    };
};
