import{G as S,H as V,I as h,a1 as y,d as A,ak as N,aN as T,al as k,j as C,ar as I,P as M}from"./ResizeObserver.es.62ab429c.js";const[_,j]=S("form"),x={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 O=A({name:_,props:x,emits:["submit","failed"],setup(o,{emit:r,slots:c}){const{children:s,linkChildren:g}=N(T),i=e=>e?s.filter(t=>e.includes(t.name)):s,v=e=>new Promise((t,n)=>{const l=[];i(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=i(e);Promise.all(l.map(a=>a.validate())).then(a=>{a=a.filter(Boolean),a.length?n(a):t()})}),P=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"?P(e):o.validateFirst?v(e):p(e),b=e=>{typeof e=="string"&&(e=[e]),i(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}),o.scrollToError&&t[0].name&&u(t[0].name)})},E=e=>{I(e),f()};return g({props:o}),k({submit:f,validate:d,scrollToField:u,resetValidation:b}),()=>{var e;return C("form",{class:j(),onSubmit:E},[(e=c.default)==null?void 0:e.call(c)])}}});const D=M(O);export{D as F};
