import{r as s,h as t,F as e}from"./p-dfbe004d.js";import{a}from"./p-7393a06c.js";import{_ as r}from"./p-8415f806.js";import"./p-fd56940f.js";import"./p-1c2e2695.js";import"./p-9a7a47e8.js";const i=class{constructor(t){s(this,t),this.open=!0,this.type="primary",this.enableValidation=!0}handleSetChange(){setTimeout((()=>{this.input&&this.input.triggerFocus()}),50)}async dismiss(){this.loading=!0,this.error="";try{await a({path:"wp/v2/users/me",method:"PATCH",data:{meta:{default_password_nag:!1}}}),this.open=!1}catch(s){this.error=(null==s?void 0:s.message)||r("Something went wrong","surecart"),this.loading=!1}}validatePassword(s){return!!new RegExp("^(?=.*?[#?!@$%^&*-]).{6,}$").test(s)}async handleSubmit(s){this.loading=!0,this.error="";try{const{password:t,password_confirm:e}=await s.target.getFormJson();if(t!==e)throw{message:r("Passwords do not match.","surecart")};if(this.enableValidation&&!this.validatePassword(t))throw{message:r("Passwords should at least 6 characters and contain one special character.","surecart")};await a({path:"wp/v2/users/me",method:"PATCH",data:{password:t,meta:{default_password_nag:!1}}}),this.dismiss(),this.success=!0}catch(s){this.error=(null==s?void 0:s.message)||r("Something went wrong","surecart"),this.loading=!1}}render(){return this.success?t("sc-alert",{type:"success",open:!0},t("span",{slot:"title"},r("Succcess!","surecart")),r("You have successfully set your password.","surecart")):t("sc-alert",{type:this.type,open:this.open,exportparts:"base, icon, text, title, message, close-icon",style:{position:"relative"}},!!this.error&&this.error,this.set?t("sc-dashboard-module",{class:"customer-details"},t("span",{slot:"heading"},r("Set A Password","surecart")," "),t("sc-button",{type:"text",size:"small",slot:"end",onClick:()=>this.set=!1},t("sc-icon",{name:"x",slot:"prefix"}),r("Cancel","surecart")),t("sc-card",null,t("sc-form",{onScFormSubmit:s=>this.handleSubmit(s)},t("sc-input",{label:r("New Password","surecart"),name:"password",type:"password",required:!0,ref:s=>this.input=s}),t("sc-input",{label:r("Confirm New Password","surecart"),name:"password_confirm",type:"password",required:!0}),t("div",null,t("sc-button",{type:"primary",full:!0,submit:!0,busy:this.loading},r("Update Password","surecart")))))):t(e,null,t("slot",{name:"title",slot:"title"},r("Reminder","surecart")),t("slot",null,r("You have not yet set a password. Please set a password for your account.","surecart")),t("sc-flex",{"justify-content":"flex-start"},t("sc-button",{size:"small",type:"primary",onClick:()=>this.set=!0},r("Set A Password","surecart")),t("sc-button",{size:"small",type:"text",onClick:()=>this.dismiss()},r("Dismiss","surecart")))),this.loading&&t("sc-block-ui",{spinner:!0}))}static get watchers(){return{set:["handleSetChange"]}}};i.style=":host{display:block}";export{i as sc_password_nag}