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:"223255b6c1beb95a587a725bb918d5ceab260d31",class:"password"},i("div",{key:"8de1b7fd8b744ac5f0e811d978e3e1ca2dcbfc3b"},i("sc-input",{key:"c8b08aed13554507f64fb4c87fd32d35384aec37",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:"2f14a2bfb864fa4e8ae9c952a367c3e2e7dfbe08",class:"password__hint"},this.hintText)),this.confirmation&&i("div",{key:"897370f510c1946fa52926b0704b0685b2c7e20c"},i("sc-input",{key:"77e19eadbc2a59958a685affe73b48bff3f7eb84",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:"5db0a19716eab276570e3e01e531459ee7e4dcb3",class:"password__hint"},this.verifyText)))}static get watchers(){return{hintText:["handleHintTextChange"]}}};r.style=a;export{r as sc_password};
//# sourceMappingURL=p-3989a8d0.entry.js.map