import{r as s,h as i}from"./p-9add63ef.js";import{s as t}from"./p-830ab1a3.js";const e=":host{display:block}.password{display:grid;gap:var(--sc-form-row-spacing, 0.75em)}.password__hint{padding-top:0.36rem;color:red}";const d=e;let a,h;const r=class{constructor(i){s(this,i);this.size="medium";this.value="";this.pill=false;this.label=undefined;this.showLabel=true;this.help="";this.placeholder=undefined;this.disabled=false;this.readonly=false;this.required=false;this.autofocus=undefined;this.confirmation=false;this.name="password";this.confirmationLabel=undefined;this.confirmationPlaceholder=undefined;this.confirmationHelp=undefined;this.enableValidation=true;this.hintText=undefined;this.verifyText=undefined}async triggerFocus(s){return this.input.triggerFocus(s)}async reportValidity(){var s,i,e,d,a,h,r;(i=(s=this.input)===null||s===void 0?void 0:s.setCustomValidity)===null||i===void 0?void 0:i.call(s,"");(d=(e=this.confirmInput)===null||e===void 0?void 0:e.setCustomValidity)===null||d===void 0?void 0:d.call(e,"");if(this.confirmation){if(((a=this.confirmInput)===null||a===void 0?void 0:a.value)&&((h=this.input)===null||h===void 0?void 0:h.value)!==((r=this.confirmInput)===null||r===void 0?void 0:r.value)){this.confirmInput.setCustomValidity(wp.i18n.__("Password does not match.","surecart"));t(wp.i18n.__("Password does not match.","surecart"),"assertive")}}if(!!this.hintText){this.input.setCustomValidity(this.hintText)}const o=await this.input.reportValidity();if(!o){return false}if(this.confirmInput){return this.confirmInput.reportValidity()}return o}handleVerification(){clearTimeout(h);h=setTimeout((()=>{this.verifyPassword()}),500)}handleValidate(){this.handleVerification();clearTimeout(a);a=setTimeout((()=>{this.validatePassword()}),500)}validatePassword(){var s,i,t;if(!this.enableValidation)return;if(((s=this.input)===null||s===void 0?void 0:s.value.trim().length)===0){this.hintText="";return}if(((i=this.input)===null||i===void 0?void 0:i.value.trim().length)<6){return this.hintText=wp.i18n.__("The password must be at least 6 characters in length.","surecart")}const e=/[-'`~!#*$@_%+=.,^&(){}[\]|;:”<>?\\]/;if(!e.test((t=this.input)===null||t===void 0?void 0:t.value)){return this.hintText=wp.i18n.__("Passwords must contain a special character.","surecart")}this.hintText=""}verifyPassword(){var s,i,e,d,a,h,r;if(((s=this.confirmInput)===null||s===void 0?void 0:s.value)&&((i=this.input)===null||i===void 0?void 0:i.value)!==((e=this.confirmInput)===null||e===void 0?void 0:e.value)){this.verifyText=wp.i18n.__("Password does not match.","surecart");t(this.verifyText,"assertive");return}if(!!((d=this.input)===null||d===void 0?void 0:d.value)&&!!((a=this.confirmInput)===null||a===void 0?void 0:a.value)&&((h=this.input)===null||h===void 0?void 0:h.value)===((r=this.confirmInput)===null||r===void 0?void 0:r.value)){t(wp.i18n.__("Password is matched.","surecart"),"assertive")}this.verifyText=""}handleHintTextChange(){t(this.hintText,"assertive")}render(){var s;return i("div",{key:"b7eb8d82c7e0bc60f15e2f9d80fadbfd7bd1cba8",class:"password"},i("div",{key:"f734f95620c2ef1fc85f7af00583f908ef80cbe7"},i("sc-input",{key:"6c1b690ba93a00d2fd84d822d0bd7b22fce03244",ref:s=>this.input=s,label:this.label,help:this.help,autofocus:this.autofocus,placeholder:this.placeholder,showLabel:this.showLabel,size:this.size?this.size:"medium",type:"password",name:"password",value:this.value,required:this.required,disabled:this.disabled,onScInput:()=>this.handleValidate()}),!!this.hintText&&i("small",{key:"7e40919a4ddf7f8762d754ddfa4f6de25effc757",class:"password__hint"},this.hintText)),this.confirmation&&i("div",{key:"e8023b5575e3c12d56736455a59993fe737fd510"},i("sc-input",{key:"1d6dc09597c22ac36973befa649e75fd425a6006",ref:s=>this.confirmInput=s,label:(s=this.confirmationLabel)!==null&&s!==void 0?s:wp.i18n.__("Confirm Password","surecart"),help:this.confirmationHelp,placeholder:this.confirmationPlaceholder,size:this.size?this.size:"medium",type:"password",value:this.value,onScInput:()=>this.handleVerification(),required:this.required,disabled:this.disabled}),!!this.verifyText&&i("small",{key:"661f281049c1c3bb545dcb134a9d7cfb1851619e",class:"password__hint"},this.verifyText)))}static get watchers(){return{hintText:["handleHintTextChange"]}}};r.style=d;export{r as sc_password};
//# sourceMappingURL=p-1afc66ec.entry.js.map