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