import{r as s,h as i}from"./p-e97fde0a.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 a=e;let d,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,a,d,h,r;(i=(s=this.input)===null||s===void 0?void 0:s.setCustomValidity)===null||i===void 0?void 0:i.call(s,"");(a=(e=this.confirmInput)===null||e===void 0?void 0:e.setCustomValidity)===null||a===void 0?void 0:a.call(e,"");if(this.confirmation){if(((d=this.confirmInput)===null||d===void 0?void 0:d.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(wp.i18n.__(this.hintText,"surecart"))}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(d);d=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,a,d,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(!!((a=this.input)===null||a===void 0?void 0:a.value)&&!!((d=this.confirmInput)===null||d===void 0?void 0:d.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:"eb46bdd0c716d0673dca1ccb7d90250a78252680",class:"password"},i("div",{key:"4a90300c2c0d298f6e972eb9e75c40af3f7bae49"},i("sc-input",{key:"48cde06662532e317ef25562ab9c98e356d8613b",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:"33a9f050392c467b4e5800a46fcb5f56c526a938",class:"password__hint"},this.hintText)),this.confirmation&&i("div",{key:"304ea37100869e4ed44f8a63042c4ec9cfca3f8e"},i("sc-input",{key:"b201524427a0a554afa1a103a27f39da6efc5cc4",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:"42b9b3ddc3a1d93afcd4a361860a379bd6586518",class:"password__hint"},this.verifyText)))}static get watchers(){return{hintText:["handleHintTextChange"]}}};r.style=a;export{r as sc_password};
//# sourceMappingURL=p-3ddd588c.entry.js.map