"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useFormWatchFields = void 0;
const react_1 = require("react");
const react_hook_form_1 = require("react-hook-form");
/**
 * Хук для отслеживания изменений значения поля формы и вызова обратного вызова при их изменении.
 *
 * @example
 * ```tsx
 * const MyComponent = () => {
 *   const { control } = useForm();
 *
 *   const onFieldChange = (value) => {
 *     console.log('Значение поля изменилось:', value);
 *   };
 *
 *   useFormWatchFields({
 *    name: 'myField',
 *    control,
 *    callback: onFieldChange
 *   });
 *
 *   return <input name="myField" />;
 * };
 * ```
 */
const useFormWatchFields = ({ name, control, callback, }) => {
    const checkIsDisabled = () => {
        if (Array.isArray(name)) {
            return !name.length;
        }
        return !name;
    };
    const value = (0, react_hook_form_1.useWatch)({ name, control, disabled: checkIsDisabled() });
    (0, react_1.useEffect)(() => {
        callback(value);
    }, [value]);
};
exports.useFormWatchFields = useFormWatchFields;
