import{A as S,E as V,G as h,$ as A,d as y,ai as N,aL as T,aj as j,j as C,ap as M,N as _}from"./index.3bfa6a0e.js";const[k,x]=S("form"),I={colon:Boolean,disabled:Boolean,readonly:Boolean,showError:Boolean,labelWidth:V,labelAlign:String,inputAlign:String,scrollToError:Boolean,validateFirst:Boolean,submitOnEnter:h,validateTrigger:A("onBlur"),showErrorMessage:h,errorMessageAlign:String};var O=y({name:k,props:I,emits:["submit","failed"],setup(i,{emit:r,slots:c}){const{children:s,linkChildren:g}=N(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=>{M(e),f()};return g({props:i}),j({submit:f,validate:d,scrollToField:u,resetValidation:P}),()=>{var e;return C("form",{class:x(),onSubmit:E},[(e=c.default)==null?void 0:e.call(c)])}}});const q=_(O);export{q as F};
