// Скопировано из https://github.com/react-hook-form/resolvers/blob/master/src/validateFieldsNatively.ts
// Причина копирования: в @hookform/resolvers react-hook-form указан как peerDep с крышкой. Из-за этого происходит рассинхрон с @astral/form
import { get, } from 'react-hook-form';
const setCustomValidity = (ref, fieldPath, errors) => {
    if (ref && 'reportValidity' in ref) {
        const error = get(errors, fieldPath);
        ref.setCustomValidity(error?.message || '');
        ref.reportValidity();
    }
};
/**
 * Native validation (web only)
 */
export const validateFieldsNatively = (errors, options) => {
    for (const fieldPath in options.fields) {
        const field = options.fields[fieldPath];
        if (field?.ref && 'reportValidity' in field.ref) {
            setCustomValidity(field.ref, fieldPath, errors);
        }
        else if (field.refs) {
            field.refs.forEach((ref) => setCustomValidity(ref, fieldPath, errors));
        }
    }
};
