import{t as w,E as y,u as g,d as A,C,S as T,W as x,c as M,a4 as N,x as _}from"./index.27735e87.js";const[I,O]=w("form"),W={colon:Boolean,disabled:Boolean,readonly:Boolean,showError:Boolean,labelWidth:y,labelAlign:String,inputAlign:String,scrollToError:Boolean,validateFirst:Boolean,submitOnEnter:g,showErrorMessage:g,errorMessageAlign:String,validateTrigger:{type:[String,Array],default:"onBlur"}};var j=A({name:I,props:W,emits:["submit","failed"],setup(i,{emit:r,slots:u}){const{children:s,linkChildren:v}=C(T),o=e=>e?s.filter(t=>e.includes(t.name)):s,p=e=>new Promise((t,n)=>{const l=[];o(e).reduce((F,V)=>F.then(()=>{if(!l.length)return V.validate().then(h=>{h&&l.push(h)})}),Promise.resolve()).then(()=>{l.length?n(l):t()})}),b=e=>new Promise((t,n)=>{const l=o(e);Promise.all(l.map(a=>a.validate())).then(a=>{a=a.filter(Boolean),a.length?n(a):t()})}),S=e=>{const t=s.find(n=>n.name===e);return t?new Promise((n,l)=>{t.validate().then(a=>{a?l(a):n()})}):Promise.reject()},c=e=>typeof e=="string"?S(e):i.validateFirst?p(e):b(e),B=e=>{typeof e=="string"&&(e=[e]),o(e).forEach(n=>{n.resetValidation()})},E=()=>s.reduce((e,t)=>(e[t.name]=t.getValidationStatus(),e),{}),d=(e,t)=>{s.some(n=>n.name===e?(n.$el.scrollIntoView(t),!0):!1)},f=()=>s.reduce((e,t)=>(e[t.name]=t.formValue.value,e),{}),m=()=>{const e=f();c().then(()=>r("submit",e)).catch(t=>{r("failed",{values:e,errors:t}),i.scrollToError&&t[0].name&&d(t[0].name)})},P=e=>{N(e),m()};return v({props:i}),x({submit:m,validate:c,getValues:f,scrollToField:d,resetValidation:B,getValidationStatus:E}),()=>{var e;return M("form",{class:O(),onSubmit:P},[(e=u.default)==null?void 0:e.call(u)])}}});const q=_(j);export{q as F};
