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