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:"e55bf763c1c769f326dc50af3062f7dc83b1351e",class:"password"},i("div",{key:"aec2b14067e20564500616e6862aedf21f0b7314"},i("sc-input",{key:"a753cad7143504fe5c0d4b6a18f269dd8a76c952",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:"256d95f6f2164c73a6f284556e6a4859db349eba",class:"password__hint"},this.hintText)),this.confirmation&&i("div",{key:"fb8f1bc1588826ac1d2c0d607f530bc4f6ae8afe"},i("sc-input",{key:"5afaa3b0ee8f0d69d02c26f7c0abd906c8fbe5bb",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:"0bdb818dda6636a8c0e83471a95518d204af6c57",class:"password__hint"},this.verifyText)))}static get watchers(){return{hintText:["handleHintTextChange"]}}};r.style=a;export{r as sc_password};
//# sourceMappingURL=p-2781e574.entry.js.map