import{h}from"@stencil/core";import{__}from"@wordpress/i18n";import apiFetch from"../../../../functions/fetch";export class ScWordPressPasswordEdit{constructor(){this.heading=void 0,this.successUrl=void 0,this.user=void 0,this.loading=void 0,this.error=void 0,this.enableValidation=!0}renderEmpty(){return h("slot",{name:"empty"},__("User not found.","surecart"))}validatePassword(e){return!!new RegExp("^(?=.*?[#?!@$%^&*-]).{6,}$").test(e)}async handleSubmit(e){this.loading=!0,this.error="";try{const{password:s}=await e.target.getFormJson();await apiFetch({path:"wp/v2/users/me",method:"PATCH",data:{password:s,meta:{default_password_nag:!1}}}),this.successUrl?window.location.assign(this.successUrl):this.loading=!1}catch(e){this.error=(null==e?void 0:e.message)||__("Something went wrong","surecart"),this.loading=!1}}render(){return h("sc-dashboard-module",{key:"40436bfd45bb8db708b2f77e9f559f26e2af0c31",class:"customer-details",error:this.error},h("span",{key:"67e4d630affbdade5bd15ce838babd41992e7a63",slot:"heading"},this.heading||__("Update Password","surecart")," "),h("slot",{key:"cd8a743ef5aa04b4d7e28a81a9c15be756230e93",name:"end",slot:"end"}),h("sc-card",{key:"496166364718b5bed56c49be6827e82b6b535be1"},h("sc-form",{key:"39103b7e7836aad2b0557719f35bafe52e44fe0b",onScFormSubmit:e=>this.handleSubmit(e)},h("sc-password",{key:"f8694d9d76b63bb0489034549d43a6d9ae2c0c1b",enableValidation:this.enableValidation,label:__("New Password","surecart"),name:"password",confirmation:!0,required:!0}),h("div",{key:"a40fa7dd4aa35adcc913881e0b113dfdf85fd68e"},h("sc-button",{key:"c986e5ba39945bc47059e571cfd6c5fb05891a3a",type:"primary",full:!0,submit:!0},__("Update Password","surecart"))))),this.loading&&h("sc-block-ui",{key:"1e11eabf4912cfa6fbf544c6aae791e2f7a6b19b",spinner:!0}))}static get is(){return"sc-wordpress-password-edit"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-wordpress-password-edit.css"]}}static get styleUrls(){return{$:["sc-wordpress-password-edit.css"]}}static get properties(){return{heading:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"heading",reflect:!1},successUrl:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"success-url",reflect:!1},user:{type:"unknown",mutable:!1,complexType:{original:"WordPressUser",resolved:"WordPressUser",references:{WordPressUser:{location:"import",path:"../../../../types",id:"src/types.ts::WordPressUser"}}},required:!1,optional:!1,docs:{tags:[],text:""}},enableValidation:{type:"boolean",mutable:!1,complexType:{original:"boolean",resolved:"boolean",references:{}},required:!1,optional:!1,docs:{tags:[],text:"Ensures strong password validation."},attribute:"enable-validation",reflect:!0,defaultValue:"true"}}}static get states(){return{loading:{},error:{}}}}