class TwoFactorAuth{constructor(t=".two-factor"){this.container=document.querySelector(t),this.container?(this.inputs=Array.from(this.container.querySelectorAll("input")),0===this.inputs.length?console.error("TwoFactorAuth: No input fields found in the container."):(this.confirmBtn=this.container.closest("form")?.querySelector('button[type="submit"]'),this.init())):console.error(`TwoFactorAuth: Container "${t}" not found.`)}init(){this.inputs[0].focus(),this.inputs.forEach((t,e)=>{t.setAttribute("inputmode","numeric"),t.setAttribute("maxlength","1"),t.addEventListener("input",t=>this.handleInput(t,e)),t.addEventListener("keydown",t=>this.handleKeyDown(t,e)),t.addEventListener("paste",this.preventPaste)}),this.confirmBtn?this.confirmBtn.addEventListener("click",t=>this.handleSubmit(t)):console.warn("TwoFactorAuth: Submit button not found.")}handleInput(t,e){let n=t.target.value.replace(/\D/g,"");1<n.length&&(n=n.charAt(0)),(this.inputs[e].value=n)&&e<this.inputs.length-1&&this.inputs[e+1].focus()}handleKeyDown(t,e){"Backspace"===t.key&&!this.inputs[e].value&&0<e&&this.inputs[e-1].focus()}preventPaste(t){t.preventDefault()}handleSubmit(t){t.preventDefault();t=this.inputs.map(t=>t.value).join("");/^\d+$/.test(t)&&t.length===this.inputs.length?console.log("Entered 2FA code:",t):(this.showError("Please enter a valid verification code."),setTimeout(()=>this.clearError(),3e3))}showError(t){this.errorSpan||(this.errorSpan=document.createElement("span"),this.errorSpan.className="text-danger d-block mb-3",this.inputs[0].parentElement.insertAdjacentElement("afterend",this.errorSpan)),this.errorSpan.textContent=t}clearError(){this.errorSpan&&(this.errorSpan.remove(),this.errorSpan=null)}}document.addEventListener("DOMContentLoaded",()=>{new TwoFactorAuth});