import{g as l,s as c,a as p}from"./index.esm-5yOGu3_l.js";var v=function(n,t,e){if(n&&"reportValidity"in n){var r=l(e,t);n.setCustomValidity(r&&r.message||""),n.reportValidity()}},d=function(n,t){var e=function(s){var i=t.fields[s];i&&i.ref&&"reportValidity"in i.ref?v(i.ref,s,n):i.refs&&i.refs.forEach(function(o){return v(o,s,n)})};for(var r in t.fields)e(r)},g=function(n,t){t.shouldUseNativeValidation&&d(n,t);var e={};for(var r in n){var s=l(t.fields,r),i=Object.assign(n[r]||{},{ref:s&&s.ref});if(y(t.names||Object.keys(n),r)){var o=Object.assign({},l(e,r));c(o,"root",i),c(e,r,o)}else c(e,r,i)}return e},y=function(n,t){return n.some(function(e){return e.startsWith(t+".")})},E=function(n,t){for(var e={};n.length;){var r=n[0],s=r.code,i=r.message,o=r.path.join(".");if(!e[o])if("unionErrors"in r){var a=r.unionErrors[0].errors[0];e[o]={message:a.message,type:a.code}}else e[o]={message:i,type:s};if("unionErrors"in r&&r.unionErrors.forEach(function(h){return h.errors.forEach(function(m){return n.push(m)})}),t){var f=e[o].types,u=f&&f[r.code];e[o]=p(o,t,e,s,u?[].concat(u,r.message):r.message)}n.shift()}return e},j=function(n,t,e){return e===void 0&&(e={}),function(r,s,i){try{return Promise.resolve(function(o,a){try{var f=Promise.resolve(n[e.mode==="sync"?"parse":"parseAsync"](r,t)).then(function(u){return i.shouldUseNativeValidation&&d({},i),{errors:{},values:e.raw?r:u}})}catch(u){return a(u)}return f&&f.then?f.then(void 0,a):f}(0,function(o){if(function(a){return a.errors!=null}(o))return{values:{},errors:g(E(o.errors,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw o}))}catch(o){return Promise.reject(o)}}};export{j as t};
