import{validateFieldsNatively as r,toNestErrors as e}from"@hookform/resolvers";import{appendErrors as o}from"react-hook-form";function s(){return s=Object.assign?Object.assign.bind():function(r){for(var e=1;e<arguments.length;e++){var o=arguments[e];for(var s in o)({}).hasOwnProperty.call(o,s)&&(r[s]=o[s])}return r},s.apply(null,arguments)}function n(r,e){const s={};for(;r.length;){const a=r[0],{code:i,message:l,path:c}=a,u=c.join(".");if(!s[u])if("unionErrors"in a){var n,t;const r=a.unionErrors.reduce((r,e)=>e.errors.length<r.errors.length?e:r).errors[0];s[u]={message:null!=(n=null==r?void 0:r.message)?n:l,type:null!=(t=null==r?void 0:r.code)?t:i}}else s[u]={message:l,type:i};if("unionErrors"in a&&a.unionErrors.forEach(e=>e.errors.forEach(e=>r.push(e))),e){const r=s[u].types,n=r&&r[a.code];s[u]=o(u,e,s,i,n?[].concat(n,a.message):a.message)}r.shift()}return s}function t(r,e){const n={};for(;r.length;){const i=r[0],{code:l,message:c,path:u}=i,d=u.join(".");if(!n[d])if("invalid_union"===i.code&&i.errors.length>0){var t,a;const r=i.errors.reduce((r,e)=>e.length<r.length?e:r)[0];n[d]={message:null!=(t=null==r?void 0:r.message)?t:c,type:null!=(a=null==r?void 0:r.code)?a:l}}else n[d]={message:c,type:l};if("invalid_union"===i.code&&i.errors.forEach(e=>e.forEach(e=>r.push(s({},e,{path:[...i.path,...e.path]})))),e){const r=n[d].types,s=r&&r[i.code];n[d]=o(d,e,n,l,s?[].concat(s,i.message):i.message)}r.shift()}return n}function a(o,s,a={}){if((r=>"_zod"in r&&"object"==typeof r._zod)(o))return async(n,i,l)=>{try{const e=o,t="sync"===a.mode?e.parse(n,s):await e.parseAsync(n,s);return l.shouldUseNativeValidation&&r({},l),{errors:{},values:a.raw?Object.assign({},n):t}}catch(r){if((r=>{var e;return!(null==r||null==(e=r._zod)||null==(e=e.traits)||!e.has("$ZodError"))})(r))return{values:{},errors:e(t(r.issues,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)};throw r}};if((r=>"_def"in r&&"object"==typeof r._def)(o))return async(t,i,l)=>{try{const e=await o["sync"===a.mode?"parse":"parseAsync"](t,s);return l.shouldUseNativeValidation&&r({},l),{errors:{},values:a.raw?Object.assign({},t):e}}catch(r){if((r=>Array.isArray(null==r?void 0:r.issues))(r))return{values:{},errors:e(n(r.errors,!l.shouldUseNativeValidation&&"all"===l.criteriaMode),l)};throw r}};throw new Error("Invalid input: not a Zod schema")}export{a as zodResolver};
//# sourceMappingURL=zod.modern.mjs.map
