import{r as i,h as t,F as o,a as c}from"./p-9add63ef.js";const e="sc-verification-code{--focus-ring:0 0 0 var(--sc-focus-ring-width) var(--sc-focus-ring-color-primary);display:block}sc-verification-code .sc-verification-code{display:flex;align-items:center;gap:var(--sc-spacing-small);margin-top:var(--sc-spacing-medium);margin-bottom:var(--sc-spacing-medium)}sc-verification-code .sc-verification-code input{flex:1;min-width:0;height:var(--sc-input-height, 48px);max-width:64px;box-sizing:border-box;font-family:var(--sc-input-font-family);font-weight:var(--sc-input-font-weight);letter-spacing:var(--sc-input-letter-spacing);background-color:var(--sc-input-background-color);border:1px solid var(--sc-input-border-color, var(--sc-input-border));border-radius:var(--sc-input-border-radius-medium);box-shadow:var(--sc-input-box-shadow);font-size:var(--sc-input-font-size-large);transition:var(--sc-input-transition, var(--sc-transition-medium)) color, var(--sc-input-transition, var(--sc-transition-medium)) border, var(--sc-input-transition, var(--sc-transition-medium)) box-shadow;cursor:text;text-align:center}sc-verification-code .sc-verification-code input:-webkit-autofill,sc-verification-code .sc-verification-code input:-webkit-autofill:hover,sc-verification-code .sc-verification-code input:-webkit-autofill:focus,sc-verification-code .sc-verification-code input:-webkit-autofill:active{box-shadow:0 0 0 var(--sc-input-height-large) var(--sc-input-background-color-hover) inset !important;-webkit-text-fill-color:var(--sc-input-color)}sc-verification-code .sc-verification-code input::placeholder{color:var(--sc-input-placeholder-color);user-select:none}sc-verification-code .sc-verification-code input:focus{outline:none;background-color:var(--sc-input-background-color-focus);border-color:var(--sc-input-border-color-focus);box-shadow:var(--focus-ring);color:var(--sc-input-color-focus);z-index:8}sc-verification-code .sc-verification-code .sc-verification-code__separator{color:var(--sc-input-help-text-color);font-size:var(--sc-font-size-large);user-select:none;display:flex;align-items:center}sc-verification-code .sc-verification-code .visually-hidden{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0, 0, 0, 0);white-space:nowrap;border:0}";const s=e;const r=class{constructor(t){i(this,t);this.filledAllInputs=()=>this.codes.join("").trim().length===this.total;this.total=6;this.codes=Array(this.total).fill("");this.loading=false;this.onChange=undefined}handleKeyDown(i,t){if(i.key==="Backspace"||i.key==="Delete"){i.preventDefault();this.getElementByIndex(t).value="";this.codes=[...this.codes.slice(0,t),"",...this.codes.slice(t+1)];if(t>0){this.focusInput(t-1)}}}handleInput(i,t){const o=i.target;let c=o.value;if(c.length>1){const i=[...this.codes];for(let o=0;o<this.total-t&&o<c.length;o++){const e=this.getElementByIndex(t+o);e.blur();e.value=c[o];i[t+o]=c[o]}this.codes=i;t=t+c.length-1;c=c[c.length-1]}if(t<this.codes.length){this.codes=[...this.codes.slice(0,t),c,...this.codes.slice(t+1)]}if(t<this.codes.length-1&&c.length>0){this.focusInput(t+1)}if(t===this.codes.length-1&&c.length>0){this.getElementByIndex(t).blur()}if(this.filledAllInputs()){this.handleCodeChange()}}handleCodeChange(){const i=(this.codes.join("")||"").trim();if(i.length===this.total){this.onChange(i)}}focusInput(i){const t=this.getElementByIndex(i);if(t){t.focus();t.select()}}async triggerFocus(){this.focusInput(0)}getElementByIndex(i){return this.el.querySelector(`#code-input-${i}`)}handleFocus(i){const t=i.target;t.select()}reset(){var i;this.codes=Array(this.total).fill("");(i=this.getElementByIndex(0))===null||i===void 0?void 0:i.focus()}render(){return t("div",{key:"134b4552986a35a342fcdf1abcd6a9070ceb3477",class:"sc-verification-code"},Array.from({length:this.total}).map(((i,c)=>t(o,null,c===Math.floor(this.total/2)&&t("span",{class:"sc-verification-code__separator","aria-hidden":"true"},"—"),t("input",{key:c,id:`code-input-${c}`,value:!!this.codes[c]?this.codes[c]:"",onInput:i=>this.handleInput(i,c),onKeyDown:i=>this.handleKeyDown(i,c),onFocus:i=>this.handleFocus(i),autocomplete:"one-time-code",inputmode:"numeric",pattern:"[0-9]*",autofocus:c===0,required:true,"aria-label":wp.i18n.__(`Verification code ${c+1} of ${this.total}`,"surecart")})))),t("button",{key:"fc6ccc0f842158fd6bc5dc395a05f979b77953e8",type:"submit",class:"visually-hidden",onClick:()=>this.onChange(this.codes.join(""))},wp.i18n.__("Submit","surecart")))}get el(){return c(this)}};r.style=s;export{r as sc_verification_code};
//# sourceMappingURL=p-f9722647.entry.js.map