import{ak as f,aA as c,aL as m,a as s,o as p,F as h,r as y,Y as g,f as v,G as T,B as k}from"./JQJBiNWj.js";import I from"./CJYlvWEf.js";import{s as b}from"./CeWG_dyW.js";import"./CDSORL4U.js";var w=({dt:e})=>`
.p-inputotp {
    display: flex;
    align-items: center;
    gap: ${e("inputotp.gap")};
}

.p-inputotp-input {
    text-align: center;
    width: ${e("inputotp.input.width")};
}

.p-inputotp-input.p-inputtext-sm {
    text-align: center;
    width: ${e("inputotp.input.sm.width")};
}

.p-inputotp-input.p-inputtext-lg {
    text-align: center;
    width: ${e("inputotp.input.lg.width")};
}
`,x={root:"p-inputotp p-component",pcInputText:"p-inputotp-input"},N=f.extend({name:"inputotp",style:w,classes:x}),P={name:"BaseInputOtp",extends:b,props:{readonly:{type:Boolean,default:!1},tabindex:{type:Number,default:null},length:{type:Number,default:4},mask:{type:Boolean,default:!1},integerOnly:{type:Boolean,default:!1}},style:N,provide:function(){return{$pcInputOtp:this,$parentInstance:this}}},B={name:"InputOtp",extends:P,inheritAttrs:!1,emits:["change","focus","blur"],data:function(){return{tokens:[]}},watch:{modelValue:{immediate:!0,handler:function(t){this.tokens=t?t.split(""):new Array(this.length)}}},methods:{getTemplateAttrs:function(t){return{value:this.tokens[t]}},getTemplateEvents:function(t){var n=this;return{input:function(r){return n.onInput(r,t)},keydown:function(r){return n.onKeyDown(r)},focus:function(r){return n.onFocus(r)},blur:function(r){return n.onBlur(r)},paste:function(r){return n.onPaste(r)}}},onInput:function(t,n){this.tokens[n]=t.target.value,this.updateModel(t),t.inputType==="deleteContentBackward"?this.moveToPrev(t):(t.inputType==="insertText"||t.inputType==="deleteContentForward"||c()&&t instanceof CustomEvent)&&this.moveToNext(t)},updateModel:function(t){var n=this.tokens.join("");this.writeValue(n,t),this.$emit("change",{originalEvent:t,value:n})},moveToPrev:function(t){var n=this.findPrevInput(t.target);n&&(n.focus(),n.select())},moveToNext:function(t){var n=this.findNextInput(t.target);n&&(n.focus(),n.select())},findNextInput:function(t){var n=t.nextElementSibling;if(n)return n.nodeName==="INPUT"?n:this.findNextInput(n)},findPrevInput:function(t){var n=t.previousElementSibling;if(n)return n.nodeName==="INPUT"?n:this.findPrevInput(n)},onFocus:function(t){t.target.select(),this.$emit("focus",t)},onBlur:function(t){this.$emit("blur",t)},onClick:function(t){setTimeout(function(){return t.target.select()},1)},onKeyDown:function(t){if(!(t.ctrlKey||t.metaKey))switch(t.code){case"ArrowLeft":this.moveToPrev(t),t.preventDefault();break;case"ArrowUp":case"ArrowDown":t.preventDefault();break;case"Backspace":t.target.value.length===0&&(this.moveToPrev(t),t.preventDefault());break;case"ArrowRight":this.moveToNext(t),t.preventDefault();break;case"Enter":case"NumpadEnter":case"Tab":break;default:(this.integerOnly&&!(t.code!=="Space"&&Number(t.key)>=0&&Number(t.key)<=9)||this.tokens.join("").length>=this.length&&t.code!=="Delete")&&t.preventDefault();break}},onPaste:function(t){var n=t.clipboardData.getData("text");if(n.length){var o=n.substring(0,this.length);(!this.integerOnly||!isNaN(o))&&(this.tokens=o.split(""),this.updateModel(t))}t.preventDefault()}},computed:{inputMode:function(){return this.integerOnly?"numeric":"text"},inputType:function(){return this.mask?"password":"text"}},components:{OtpInputText:I}};function D(e,t,n,o,r,i){var l=m("OtpInputText");return p(),s("div",k({class:e.cx("root")},e.ptmi("root")),[(p(!0),s(h,null,y(e.length,function(a){return g(e.$slots,"default",{key:a,events:i.getTemplateEvents(a-1),attrs:i.getTemplateAttrs(a-1),index:a},function(){return[v(l,{value:r.tokens[a-1],type:i.inputType,class:T(e.cx("pcInputText")),name:e.$formName,inputmode:i.inputMode,variant:e.variant,readonly:e.readonly,disabled:e.disabled,size:e.size,invalid:e.invalid,tabindex:e.tabindex,unstyled:e.unstyled,onInput:function(d){return i.onInput(d,a-1)},onFocus:t[0]||(t[0]=function(u){return i.onFocus(u)}),onBlur:t[1]||(t[1]=function(u){return i.onBlur(u)}),onPaste:t[2]||(t[2]=function(u){return i.onPaste(u)}),onKeydown:t[3]||(t[3]=function(u){return i.onKeyDown(u)}),onClick:t[4]||(t[4]=function(u){return i.onClick(u)}),pt:e.ptm("pcInputText")},null,8,["value","type","class","name","inputmode","variant","readonly","disabled","size","invalid","tabindex","unstyled","onInput","pt"])]})}),128))],16)}B.render=D;export{B as default};
