var N=Object.defineProperty,A=Object.defineProperties;var F=Object.getOwnPropertyDescriptors;var v=Object.getOwnPropertySymbols;var x=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var O=(s,r,a)=>r in s?N(s,r,{enumerable:!0,configurable:!0,writable:!0,value:a}):s[r]=a,R=(s,r)=>{for(var a in r||(r={}))x.call(r,a)&&O(s,a,r[a]);if(v)for(var a of v(r))B.call(r,a)&&O(s,a,r[a]);return s},S=(s,r)=>A(s,F(r));var V=(s,r)=>{var a={};for(var t in s)x.call(s,t)&&r.indexOf(t)<0&&(a[t]=s[t]);if(s!=null&&v)for(var t of v(s))r.indexOf(t)<0&&B.call(s,t)&&(a[t]=s[t]);return a};var j=(s,r,a)=>new Promise((t,m)=>{var T=f=>{try{g(a.next(f))}catch(h){m(h)}},u=f=>{try{g(a.throw(f))}catch(h){m(h)}},g=f=>f.done?t(f.value):Promise.resolve(f.value).then(T,u);g((a=a.apply(s,r)).next())});import{d as G,bC as H,bD as J,aM as K,af as W,t as X,w as Y,f as z,o as $,g as L,k as Q,J as U,bE as Z,n as ee,a2 as se,ai as ae,al as y,aX as oe,be as te,b5 as re,bz as le,j as ne,q as pe}from"./index-C8qz7c0N.js";const ie={name:"wd-form",options:{addGlobalClass:!0,virtualHost:!0,styleIsolation:"shared"}},fe=G(S(R({},ie),{props:H,setup(s,{expose:r}){const{show:a}=J("wd-form-toast"),t=s,{children:m,linkChildren:T}=K(W);let u=X({});T({props:t,errorMessages:u}),Y(()=>t.model,()=>{t.resetOnChange&&w()},{immediate:!0,deep:!0});function g(o){return j(this,null,function*(){const l=[];let e=!0;const n=[],_=f(),b=ae(o)?o:y(o)?[o]:[],P=b.length>0?b.reduce((p,d)=>(_[d]&&(p[d]=_[d]),p),{}):_;for(const p in P){const d=P[p],C=oe(t.model,p);if(d&&d.length>0)for(const i of d){if(i.required&&(!y(C)||C==="")){l.push({prop:p,message:i.message}),e=!1;break}if(i.pattern&&!i.pattern.test(C)){l.push({prop:p,message:i.message}),e=!1;break}const k=i,{validator:M}=k,D=V(k,["validator"]);if(M){const E=M(C,D);te(E)?n.push(E.then(c=>{typeof c=="string"?(l.push({prop:p,message:c}),e=!1):typeof c=="boolean"&&!c&&(l.push({prop:p,message:i.message}),e=!1)}).catch(c=>{const I=y(c)?re(c)?c:c.message||i.message:i.message;l.push({prop:p,message:I}),e=!1})):E||(l.push({prop:p,message:i.message}),e=!1)}}}return yield Promise.all(n),h(l),e&&(b.length?b.forEach(w):w()),{valid:e,errors:l}})}function f(){const o=le(t.rules),l=m.map(e=>e.prop);return Object.keys(o).forEach(e=>{l.includes(e)||delete o[e]}),m.forEach(e=>{y(e.prop)&&y(e.rules)&&e.rules.length&&(o[e.prop]?o[e.prop]=[...o[e.prop],...e.rules]:o[e.prop]=e.rules)}),o}function h(o){const l=m.map(n=>n.prop).filter(Boolean),e=o.filter(n=>n.message&&l.includes(n.prop));e.length&&(e.sort((n,_)=>l.indexOf(n.prop)-l.indexOf(_.prop)),t.errorType==="toast"?a(e[0].message):t.errorType==="message"&&e.forEach(n=>{u[n.prop]=n.message}))}function w(o){o?u[o]="":Object.keys(u).forEach(l=>{u[l]=""})}function q(){w()}return r({validate:g,reset:q}),(o,l)=>{const e=ne;return $(),z(e,{class:se(`wd-form ${o.customClass}`),style:ee(o.customStyle)},{default:L(()=>[Q(o.$slots,"default",{},void 0,!0),t.errorType==="toast"?($(),z(Z,{key:0,selector:"wd-form-toast"})):U("",!0)]),_:3},8,["class","style"])}}})),de=pe(fe,[["__scopeId","data-v-e513a788"]]);export{de as _};
