import{L as w,M as h,R as y,O as T,Q as A,ax as M,e as x,a$ as C,a2 as N,W as O}from"./index-BDh_pN-M.js";const[_,k]=T("form"),q={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 I=w({name:_,props:q,emits:["submit","failed"],setup(i,{emit:s,slots:c}){const{children:a,linkChildren:v}=A(C),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()})}),b=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()})}),P=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"?P(e):i.validateFirst?p(e):b(e),S=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=>{N(e),m()};return v({props:i}),M({submit:m,validate:d,getValues:f,scrollToField:u,resetValidation:S,getValidationStatus:B}),()=>{var e;return x("form",{class:k(),onSubmit:E},[(e=c.default)==null?void 0:e.call(c)])}}});const W=O(I);export{W as F};
