import{g as h,s as d,f as b}from"./form-rPxRlXL8.js";import{p as V,f as O,$ as w}from"./schemas-IctYPUjJ.js";const g=(n,s,r)=>{if(n&&"reportValidity"in n){const e=h(r,s);n.setCustomValidity(e&&e.message||""),n.reportValidity()}},p=(n,s)=>{for(const r in s.fields){const e=s.fields[r];e&&e.ref&&"reportValidity"in e.ref?g(e.ref,r,n):e&&e.refs&&e.refs.forEach(o=>g(o,r,n))}},y=(n,s)=>{s.shouldUseNativeValidation&&p(n,s);const r={};for(const e in n){const o=h(s.fields,e),i=Object.assign(n[e]||{},{ref:o&&o.ref});if(P(s.names||Object.keys(n),e)){const t=Object.assign({},h(r,e));d(t,"root",i),d(r,e,t)}else d(r,e,i)}return r},P=(n,s)=>{const r=j(s).replace(/[.*+?^${}()|\\]/g,"\\$&");return n.some(e=>j(e).match(`^${r}\\.\\d+`))};function j(n){return n.replace(/[\[\]]/g,"")}function m(){return m=Object.assign?Object.assign.bind():function(n){for(var s=1;s<arguments.length;s++){var r=arguments[s];for(var e in r)({}).hasOwnProperty.call(r,e)&&(n[e]=r[e])}return n},m.apply(null,arguments)}function E(n,s){try{var r=n()}catch(e){return s(e)}return r&&r.then?r.then(void 0,s):r}function _(n,s){for(var r={};n.length;){var e=n[0],o=e.code,i=e.message,t=e.path.join(".");if(!r[t])if("unionErrors"in e){var a=e.unionErrors[0].errors[0];r[t]={message:a.message,type:a.code}}else r[t]={message:i,type:o};if("unionErrors"in e&&e.unionErrors.forEach(function(f){return f.errors.forEach(function(l){return n.push(l)})}),s){var c=r[t].types,u=c&&c[e.code];r[t]=b(t,s,r,o,u?[].concat(u,e.message):e.message)}n.shift()}return r}function N(n,s){for(var r={},e=function(){var o=n[0],i=o.code,t=o.message,a=o.path.join(".");if(!r[a])if(o.code==="invalid_union"&&o.errors.length>0){var c=o.errors[0][0];r[a]={message:c.message,type:c.code}}else r[a]={message:t,type:i};if(o.code==="invalid_union"&&o.errors.forEach(function(l){return l.forEach(function(v){return n.push(m({},v,{path:[].concat(o.path,v.path)}))})}),s){var u=r[a].types,f=u&&u[o.code];r[a]=b(a,s,r,i,f?[].concat(f,o.message):o.message)}n.shift()};n.length;)e();return r}function A(n,s,r){if(r===void 0&&(r={}),(function(e){return"_def"in e&&typeof e._def=="object"&&"typeName"in e._def})(n))return function(e,o,i){try{return Promise.resolve(E(function(){return Promise.resolve(n[r.mode==="sync"?"parse":"parseAsync"](e,s)).then(function(t){return i.shouldUseNativeValidation&&p({},i),{errors:{},values:r.raw?Object.assign({},e):t}})},function(t){if((function(a){return Array.isArray(a?.issues)})(t))return{values:{},errors:y(_(t.errors,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw t}))}catch(t){return Promise.reject(t)}};if((function(e){return"_zod"in e&&typeof e._zod=="object"})(n))return function(e,o,i){try{return Promise.resolve(E(function(){return Promise.resolve((r.mode==="sync"?V:O)(n,e,s)).then(function(t){return i.shouldUseNativeValidation&&p({},i),{errors:{},values:r.raw?Object.assign({},e):t}})},function(t){if((function(a){return a instanceof w})(t))return{values:{},errors:y(N(t.issues,!i.shouldUseNativeValidation&&i.criteriaMode==="all"),i)};throw t}))}catch(t){return Promise.reject(t)}};throw new Error("Invalid input: not a Zod schema")}export{A as u};
