"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const P=require("../../node_modules/.pnpm/async-validator@4.2.5/node_modules/async-validator/dist-web/index.js"),R=require("vue"),F=require("../../_util/props-util/index.js"),b=require("./messages.js"),O=require("./valueUtil.js"),V=P.default;function $(n,r){return n.replace(/\$\{\w+\}/g,i=>{const u=i.slice(2,-1);return r[u]})}async function w(n,r,i,u,c){const o={...i};delete o.ruleIndex,delete o.trigger;let h=null;o&&o.type==="array"&&o.defaultField&&(h=o.defaultField,delete o.defaultField);const m=new V({[n]:[o]}),d=O.setValues({},b.defaultValidateMessages,u.validateMessages);m.messages(d);let e=[];try{await Promise.resolve(m.validate({[n]:r},{...u}))}catch(t){t.errors?e=t.errors.map(({message:s},f)=>F.isValidElement(s)?R.cloneVNode(s,{key:`error_${f}`}):s):(console.error(t),e=[d.default()])}if(!e.length&&h)return(await Promise.all(r.map((s,f)=>w(`${n}.${f}`,s,h,u,c)))).reduce((s,f)=>[...s,...f],[]);const l={...i,name:n,enum:(i.enum||[]).join(", "),...c};return e.map(t=>typeof t=="string"?$(t,l):t)}function j(n,r,i,u,c,o){const h=n.join("."),m=i.map((e,l)=>{const a=e.validator,t={...e,ruleIndex:l};return a&&(t.validator=(s,f,g)=>{let p=!1;const y=a(s,f,(...v)=>{Promise.resolve().then(()=>{p||g(...v)})});p=y&&typeof y.then=="function"&&typeof y.catch=="function",p&&y.then(()=>{g()}).catch(v=>{g(v||" ")})}),t}).sort(({warningOnly:e,ruleIndex:l},{warningOnly:a,ruleIndex:t})=>!!e==!!a?l-t:e?1:-1);let d;if(c===!0)d=new Promise(async(e,l)=>{for(let a=0;a<m.length;a+=1){const t=m[a],s=await w(h,r,t,u,o);if(s.length){l([{errors:s,rule:t}]);return}}e([])});else{const e=m.map(l=>w(h,r,l,u,o).then(a=>({errors:a,rule:l})));d=(c?x(e):q(e)).then(l=>Promise.reject(l))}return d.catch(e=>e),d}async function q(n){return Promise.all(n).then(r=>[].concat(...r))}async function x(n){let r=0;return new Promise(i=>{n.forEach(u=>{u.then(c=>{c.errors.length&&i([c]),r+=1,r===n.length&&i([])})})})}exports.validateRules=j;
