import{d as t,a0 as e,a3 as a,F as s,af as i,a1 as n,v as r,ak as o}from"./vendor-C4fU48ba.js";import{_ as h}from"./index-Dy4pwQz7.js";const c=t({props:["ct"],data:()=>({loading:!1}),computed:{getCtData(){return this.ct},ctSize(){return this.getCtData.length},cIndex(){let t=this.getCtData.findIndex(t=>""===t);return t=(t+this.ctSize)%this.ctSize,t},lastCode(){return this.getCtData[this.ctSize-1]}},watch:{cIndex(){this.resetCaret()},lastCode(t,e){t&&t!=e&&(this.$refs.input[this.ctSize-1].blur(),this.sendCaptcha())}},mounted(){this.resetCaret()},methods:{onInput(t,e){if(t=String(t).replace(/\D/g,""),this.getCtData[e]=t,e==this.ctSize-1)this.getCtData[this.ctSize-1]=t[0];else if(t.length>1){let a=e;for(a=e;a<this.ctSize&&a-e<t.length;a++)this.getCtData[a]=t[a];this.resetCaret()}else t+""||(this.getCtData[e]="")},resetCaret(){this.$refs.input[this.ctSize-1].focus()},onFocus(){let t=this.getCtData.findIndex(t=>""===t);t=(t+this.ctSize)%this.ctSize,this.$refs.input[t].focus()},onKeypress(t){const e=String.fromCharCode(t.which);/[0-9]/.test(e)||t.preventDefault()},onKeydown(t,e){if("Backspace"===t.key||"Delete"===t.key){""===t.target.value&&e>0&&(this.getCtData[e-1]="",this.$refs.input[e-1].focus())}else!t.key||/[0-9]/.test(t.key)||["Backspace","Delete","Tab","Enter","ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(t.key)||t.preventDefault()},sendCaptcha(){let t=this.getCtData.map(t=>t).join("");this.$emit("sendCaptcha",t)},reset(){this.getCtData=this.getCtData.map(t=>""),this.resetCaret()}}}),d={id:"app"},p={class:"captcha"},u=["onUpdate:modelValue","onInput","onKeydown","disabled"];const l=h(c,[["render",function(t,h,c,l,C,g){return n(),e("div",d,[a("div",p,[(n(!0),e(s,null,i(t.getCtData,(a,s)=>r((n(),e("input",{key:s,type:"text","onUpdate:modelValue":e=>t.getCtData[s]=e,ref_for:!0,ref:"input",inputmode:"numeric",pattern:"[0-9]*",onInput:e=>{t.onInput(e.target.value,s)},onKeydown:e=>{t.onKeydown(e,s)},onKeypress:h[0]||(h[0]=e=>{t.onKeypress(e)}),onFocus:h[1]||(h[1]=(...e)=>t.onFocus&&t.onFocus(...e)),disabled:t.loading},null,40,u)),[[o,t.getCtData[s]]])),128))])])}],["__scopeId","data-v-01884fd1"]]);export{l as V};
