import{t as w,z as y,v as g,d as A,x as T,S as x,W as C,c as M,a4 as N,D as _}from"./index.d1dca38b.js";const[D,I]=w("form"),O={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 W=A({name:D,props:O,emits:["submit","failed"],setup(i,{emit:r,slots:c}){const{children:s,linkChildren:v}=T(x),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()},d=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()})},P=()=>s.reduce((e,t)=>(e[t.name]=t.getValidationStatus(),e),{}),u=(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();d().then(()=>r("submit",e)).catch(t=>{r("failed",{values:e,errors:t}),i.scrollToError&&t[0].name&&u(t[0].name)})},E=e=>{N(e),m()};return v({props:i}),C({submit:m,validate:d,getValues:f,scrollToField:u,resetValidation:B,getValidationStatus:P}),()=>{var e;return M("form",{class:I(),onSubmit:E},[(e=c.default)==null?void 0:e.call(c)])}}});const k=_(W);export{k as F};
