import{h}from"@stencil/core";import{__}from"@wordpress/i18n";import apiFetch from"../../../../functions/fetch";export class ScWordPressUserEdit{constructor(){this.heading=void 0,this.successUrl=void 0,this.user=void 0,this.loading=void 0,this.error=void 0}renderEmpty(){return h("slot",{name:"empty"},__("User not found.","surecart"))}async handleSubmit(e){this.loading=!0;try{const{email:s,first_name:t,last_name:r,name:a}=await e.target.getFormJson();await apiFetch({path:"wp/v2/users/me",method:"PATCH",data:{first_name:t,last_name:r,email:s,name:a}}),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(){var e,s,t,r;return h("sc-dashboard-module",{key:"c873dbb5fde98599e5469626735155dd8bad7347",class:"account-details",error:this.error},h("span",{key:"d7d61fdb81f9b4672309040f2339a46ca64f6ae5",slot:"heading"},this.heading||__("Account Details","surecart")," "),h("sc-card",{key:"11154dd3e85dba90aa52a9cc1d37994b96fb60b6"},h("sc-form",{key:"574de64fc392ee2666346c708a22307a9f9bc74f",onScFormSubmit:e=>this.handleSubmit(e)},h("sc-input",{key:"8cf5f349b6aaf151e64319faf462693cf18a8691",label:__("Account Email","surecart"),name:"email",value:null===(e=this.user)||void 0===e?void 0:e.email,required:!0}),h("sc-columns",{key:"068c84390f8871b706c3d8a83b59f620f3e76658",style:{"--sc-column-spacing":"var(--sc-spacing-medium)"}},h("sc-column",{key:"f17d8a8ebe2c82c987c874116093dd631b48c385"},h("sc-input",{key:"a77b538cacd3a3e197d976718b9d9e8cdecd8212",label:__("First Name","surecart"),name:"first_name",value:null===(s=this.user)||void 0===s?void 0:s.first_name})),h("sc-column",{key:"31aacae027df0c438de6f2d67f4c98535c7bda83"},h("sc-input",{key:"1e029f07eebe636c0f7ff4e74467bd5e19a2b68f",label:__("Last Name","surecart"),name:"last_name",value:null===(t=this.user)||void 0===t?void 0:t.last_name}))),h("sc-input",{key:"8bbf1f99c7762be03b647b13c383a196c209ac19",label:__("Display Name","surecart"),name:"name",value:null===(r=this.user)||void 0===r?void 0:r.display_name}),h("div",{key:"a57a6edf2fa15be6c2956b278080cab5f210e9f4"},h("sc-button",{key:"dc5421f2837ef791029837d822c7bfb6aecbfe85",type:"primary",full:!0,submit:!0},__("Save","surecart"))))),this.loading&&h("sc-block-ui",{key:"8a56afc8a96ed6c01e1b5691f8753fb7c5bb7892",spinner:!0}))}static get is(){return"sc-wordpress-user-edit"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-wordpress-user-edit.css"]}}static get styleUrls(){return{$:["sc-wordpress-user-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:""}}}}static get states(){return{loading:{},error:{}}}}