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