"use strict";const i=require("vue"),a=require("../Shared/base-iCmnU-fv.js"),d=require("../Shared/index-Ul6uY51t.js");require("js-cookie");require("decimal.js");class S{startTime;startPos;endPos;duration;runEasing;runIngFun;lastPos;lastInterval;timeAnimate;constructor(s){this.startTime=0,this.startPos=0,this.endPos=0,this.duration=0,this.runEasing=null,this.runIngFun=s.runIngCallback,this.lastPos=0,this.lastInterval=0}_easing={linear:(s,t,r,l)=>r*s/l+t,easeInCubic:(s,t,r,l)=>r*(s/=l)*s*s+t,easeOutCubic:(s,t,r,l)=>r*((s=s/l-1)*s*s+1)+t};start(s,t,r,l="linear"){const o=this;return new Promise(f=>{this.startTime=+new Date,this.startPos=s,this.endPos=t,this.duration=r,this.runEasing=o._easing[l],o.timeAnimate=a.CommonBase.requestAnimationFrame(function p(){o.step()===!1?(o.stop(),f(o.lastInterval)):o.timeAnimate=a.CommonBase.requestAnimationFrame(p)})})}step(){const s=+new Date;if(s>=this.startTime+this.duration)return this.runIngFun(this.endPos),!1;const t=this.runEasing(s-this.startTime,this.startPos,this.endPos-this.startPos,this.duration);return this.lastInterval=Math.abs(t-this.lastPos),this.lastPos=t,this.runIngFun(t),!0}stop(){this.timeAnimate&&a.CommonBase.cancelAnimationFrame(this.timeAnimate)}}const A=i.defineComponent({name:"ClForm",__name:"Index",props:{theme:{},className:{},isAwaitRun:{type:Boolean},preScroll:{},pElError:{},isScrollToErr:{type:Boolean}},setup(E,{expose:s}){const t=E,r=i.ref(null),l=i.reactive({isRun:!t.isAwaitRun}),o={_scrollUpAnimate:null,parentScroll:null,isScrollWindow:!0},f=i.computed(()=>{const e={"data-cl-validate":""};return l.isRun&&(e["data-run"]=""),a.CommonBase.isEmpty(t.theme)||(e["data-theme"]=t.theme),e}),p=i.computed(()=>{const e={"panel-form":!0,"form-validate":!0};return t.className&&!a.CommonBase.isEmpty(t.className)&&t.className.split(" ").forEach(n=>{a.CommonBase.isEmpty(n)||(e[n]=!0)}),e}),h=e=>{let n=!0;return l.isRun&&!a.CommonBase.isUndefined(e)&&r.value?.contains(e)&&e.runValidate&&(n=e.runValidate()),n},P=()=>{const e=r.value?.querySelectorAll("[data-validate-error]");if(!a.CommonBase.isUndefined(e)&&e.length&&e.length>0){let n=e[0];const{preScroll:m,pElError:c}=t,u=!a.CommonBase.isEmpty(n.pElError),C=!a.CommonBase.isEmpty(c);if(u||C){const v=d.CommonElement.getParent(n,u?n.pElError:c,r.value);a.CommonBase.isUndefined(v)||(n=v)}let g=d.CommonElement.getOffset(n,o.isScrollWindow?null:o.parentScroll).top-10;m&&!a.CommonBase.isUndefined(m)&&(g-=m),o._scrollUpAnimate.start(o.parentScroll.scrollTop,g,200)}},B=()=>{const e=d.CommonElement.getParentScrollList(r.value,null,!1);o.isScrollWindow=e.length===0,o.parentScroll=o.isScrollWindow?document.documentElement:e[0].children[0],o._scrollUpAnimate=new S({runIngCallback:n=>{o.parentScroll.scrollTop=n}})};return i.onMounted(()=>{i.nextTick(()=>{B()})}),s({validate:e=>d.CommonPromise.promiseFun(n=>{let m=!0;a.CommonBase.isUndefined(e)?(l.isRun=!0,i.nextTick(()=>{const c=r.value?.querySelectorAll("[data-validate-el]");!a.CommonBase.isUndefined(c)&&c.length&&c.length>0&&c.forEach(u=>{h(u)||(m=!1)}),m||t.isScrollToErr&&i.nextTick(()=>{P()}),n(m)})):(m=h(e),n(m))}),reset:()=>{l.isRun=!1,r.value?.removeAttribute("data-run");const e=r.value?.querySelectorAll("[data-validate-el]");!a.CommonBase.isUndefined(e)&&e.length&&e.length>0&&e.forEach(n=>{n.runReset&&n.runReset()})}}),(e,n)=>(i.openBlock(),i.createElementBlock("form",i.mergeProps({ref_key:"refElTop",ref:r,autocomplete:"off",class:p.value},f.value),[i.renderSlot(e.$slots,"default")],16))}});module.exports=A;
//# sourceMappingURL=ClForm.cjs.map
