import{r as s,h as r}from"./p-dfbe004d.js";import{_ as t}from"./p-8415f806.js";import"./p-fd56940f.js";import{a}from"./p-7393a06c.js";import"./p-9a7a47e8.js";import"./p-1c2e2695.js";const e=class{constructor(r){s(this,r),this.enableValidation=!0}renderEmpty(){return r("slot",{name:"empty"},t("User not found.","surecart"))}validatePassword(s){return!!new RegExp("^(?=.*?[#?!@$%^&*-]).{6,}$").test(s)}async handleSubmit(s){this.loading=!0,this.error="";try{const{password:r,password_confirm:e}=await s.target.getFormJson();if(r!==e)throw{message:t("Passwords do not match.","surecart")};if(this.enableValidation&&!this.validatePassword(r))throw{message:t("Passwords should at least 6 characters and contain one special character.","surecart")};await a({path:"wp/v2/users/me",method:"PATCH",data:{password:r,meta:{default_password_nag:!1}}}),this.successUrl?window.location.assign(this.successUrl):this.loading=!1}catch(s){this.error=(null==s?void 0:s.message)||t("Something went wrong","surecart"),this.loading=!1}}render(){return r("sc-dashboard-module",{class:"customer-details",error:this.error},r("span",{slot:"heading"},this.heading||t("Update Password","surecart")," "),r("slot",{name:"end",slot:"end"}),r("sc-card",null,r("sc-form",{onScFormSubmit:s=>this.handleSubmit(s)},r("sc-input",{label:t("New Password","surecart"),name:"password",type:"password",required:!0}),r("sc-input",{label:t("Confirm New Password","surecart"),name:"password_confirm",type:"password",required:!0}),r("div",null,r("sc-button",{type:"primary",full:!0,submit:!0},t("Update Password","surecart"))))),this.loading&&r("sc-block-ui",{spinner:!0}))}};e.style=":host{display:block;position:relative}";export{e as sc_wordpress_password_edit}