import{ar as C,a as P,aS as q,aT as A,o as R,as as V,at as B,aE as I,aR as Q,aU as g,aV as j,aW as D,aX as O,aY as T}from"./index-OSKNspXo.js";const K=C({name:"QForm",props:{autofocus:Boolean,noErrorFocus:Boolean,noResetFocus:Boolean,greedy:Boolean,onSubmit:Function},emits:["reset","validationSuccess","validationError"],setup(r,{slots:E,emit:l}){const F=V(),u=P(null);let i=0;const s=[];function d(e){const a=typeof e=="boolean"?e:r.noErrorFocus!==!0,f=++i,x=(t,o)=>{l(`validation${t===!0?"Success":"Error"}`,o)},h=t=>{const o=t.validate();return typeof o.then=="function"?o.then(n=>({valid:n,comp:t}),n=>({valid:!1,comp:t,err:n})):Promise.resolve({valid:o,comp:t})};return(r.greedy===!0?Promise.all(s.map(h)).then(t=>t.filter(o=>o.valid!==!0)):s.reduce((t,o)=>t.then(()=>h(o).then(n=>{if(n.valid===!1)return Promise.reject(n)})),Promise.resolve()).catch(t=>[t])).then(t=>{if(t===void 0||t.length===0)return f===i&&x(!0),!0;if(f===i){const{comp:o,err:n}=t[0];if(n!==void 0&&console.error(n),x(!1,o),a===!0){const S=t.find(({comp:p})=>typeof p.focus=="function"&&Q(p.$)===!1);S!==void 0&&S.comp.focus()}}return!1})}function m(){i++,s.forEach(e=>{typeof e.resetValidation=="function"&&e.resetValidation()})}function v(e){e!==void 0&&g(e);const a=i+1;d().then(f=>{a===i&&f===!0&&(r.onSubmit!==void 0?l("submit",e):(e==null?void 0:e.target)!==void 0&&typeof e.target.submit=="function"&&e.target.submit())})}function b(e){e!==void 0&&g(e),l("reset"),j(()=>{m(),r.autofocus===!0&&r.noResetFocus!==!0&&c()})}function c(){D(()=>{if(u.value===null)return;const e=u.value.querySelector("[autofocus][tabindex], [data-autofocus][tabindex]")||u.value.querySelector("[autofocus] [tabindex], [data-autofocus] [tabindex]")||u.value.querySelector("[autofocus], [data-autofocus]")||Array.prototype.find.call(u.value.querySelectorAll("[tabindex]"),a=>a.tabIndex!==-1);e==null||e.focus({preventScroll:!0})})}O(T,{bindComponent(e){s.push(e)},unbindComponent(e){const a=s.indexOf(e);a!==-1&&s.splice(a,1)}});let y=!1;return q(()=>{y=!0}),A(()=>{y===!0&&r.autofocus===!0&&c()}),R(()=>{r.autofocus===!0&&c()}),Object.assign(F.proxy,{validate:d,resetValidation:m,submit:v,reset:b,focus:c,getValidationComponents:()=>s}),()=>B("form",{class:"q-form",ref:u,onSubmit:v,onReset:b},I(E.default))}});export{K as Q};
//# sourceMappingURL=QForm-PGP8CIo6.js.map
