import{proxyCustomElement,HTMLElement,h}from"@stencil/core/internal/client";import"./fetch.js";import{d as defineCustomElement$d}from"./sc-alert2.js";import{d as defineCustomElement$c}from"./sc-block-ui2.js";import{d as defineCustomElement$b}from"./sc-button2.js";import{d as defineCustomElement$a}from"./sc-card2.js";import{d as defineCustomElement$9}from"./sc-dashboard-module2.js";import{d as defineCustomElement$8}from"./sc-form2.js";import{d as defineCustomElement$7}from"./sc-form-control2.js";import{d as defineCustomElement$6}from"./sc-icon2.js";import{d as defineCustomElement$5}from"./sc-input2.js";import{d as defineCustomElement$4}from"./sc-password2.js";import{d as defineCustomElement$3}from"./sc-spinner2.js";import{d as defineCustomElement$2}from"./sc-visually-hidden2.js";import{a as apiFetch}from"./index4.js";const scWordpressPasswordEditCss=":host{display:block;position:relative}",ScWordpressPasswordEditStyle0=scWordpressPasswordEditCss,ScWordPressPasswordEdit=proxyCustomElement(class extends HTMLElement{constructor(){super(),this.__registerHost(),this.__attachShadow(),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"},wp.i18n.__("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)||wp.i18n.__("Something went wrong","surecart"),this.loading=!1}}render(){return h("sc-dashboard-module",{key:"feddccbc9dd30c4f3a70c24d6e25ad69d8ac47fd",class:"customer-details",error:this.error},h("span",{key:"c783193ecf26bf812f46a17aa5d49f4647f24985",slot:"heading"},this.heading||wp.i18n.__("Update Password","surecart")," "),h("slot",{key:"85613aff2a44140892c3b2d3ea1e7e6fd76cb69e",name:"end",slot:"end"}),h("sc-card",{key:"d3f20009f4d1f3f2c588b6372da95965a1e6bbb8"},h("sc-form",{key:"51bfc24a84809d1b95a593e5c26ab7bc73dd464f",onScFormSubmit:e=>this.handleSubmit(e)},h("sc-password",{key:"e106ef9551824fa86ddbe2e8a738cd5f630230a6",enableValidation:this.enableValidation,label:wp.i18n.__("New Password","surecart"),name:"password",confirmation:!0,required:!0}),h("div",{key:"86e8eb9cb1269515ff05ae9c82823847a1953919"},h("sc-button",{key:"f533e96120143bf8d79c2e7dd5cf3788befe6c5a",type:"primary",full:!0,submit:!0},wp.i18n.__("Update Password","surecart"))))),this.loading&&h("sc-block-ui",{key:"acca448a76b4c6ded2ff7ba90395adaa182e834a",spinner:!0}))}static get style(){return ScWordpressPasswordEditStyle0}},[1,"sc-wordpress-password-edit",{heading:[1],successUrl:[1,"success-url"],user:[16],enableValidation:[516,"enable-validation"],loading:[32],error:[32]}]);function defineCustomElement$1(){"undefined"!=typeof customElements&&["sc-wordpress-password-edit","sc-alert","sc-block-ui","sc-button","sc-card","sc-dashboard-module","sc-form","sc-form-control","sc-icon","sc-input","sc-password","sc-spinner","sc-visually-hidden"].forEach((e=>{switch(e){case"sc-wordpress-password-edit":customElements.get(e)||customElements.define(e,ScWordPressPasswordEdit);break;case"sc-alert":customElements.get(e)||defineCustomElement$d();break;case"sc-block-ui":customElements.get(e)||defineCustomElement$c();break;case"sc-button":customElements.get(e)||defineCustomElement$b();break;case"sc-card":customElements.get(e)||defineCustomElement$a();break;case"sc-dashboard-module":customElements.get(e)||defineCustomElement$9();break;case"sc-form":customElements.get(e)||defineCustomElement$8();break;case"sc-form-control":customElements.get(e)||defineCustomElement$7();break;case"sc-icon":customElements.get(e)||defineCustomElement$6();break;case"sc-input":customElements.get(e)||defineCustomElement$5();break;case"sc-password":customElements.get(e)||defineCustomElement$4();break;case"sc-spinner":customElements.get(e)||defineCustomElement$3();break;case"sc-visually-hidden":customElements.get(e)||defineCustomElement$2()}}))}const ScWordpressPasswordEdit=ScWordPressPasswordEdit,defineCustomElement=defineCustomElement$1;export{ScWordpressPasswordEdit,defineCustomElement};