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:a,last_name:t,name:r}=await e.target.getFormJson();await apiFetch({path:"wp/v2/users/me",method:"PATCH",data:{first_name:a,last_name:t,email:s,name:r}}),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,a,t;return h("sc-dashboard-module",{key:"a422ba1c2c1db4ed6e679a7df550166caed0c3e2",class:"account-details",error:this.error},h("span",{key:"8b2162a34f54e40b4c2ae5b5e052b854497cbea3",slot:"heading"},this.heading||__("Account Details","surecart")," "),h("sc-card",{key:"de88b6807a5421cf9e609ad3a53563f8867bb4ca"},h("sc-form",{key:"cf27c3856c9d83654901e62ddc8d10e9bd0b70b3",onScFormSubmit:e=>this.handleSubmit(e)},h("sc-input",{key:"dc6a23f37ec0f66bc62c752286c7931eb1b9050d",label:__("Account Email","surecart"),name:"email",value:null===(e=this.user)||void 0===e?void 0:e.email,required:!0}),h("sc-columns",{key:"2984ad09bac241bf613b2c1829f71cd339c13271",style:{"--sc-column-spacing":"var(--sc-spacing-medium)"}},h("sc-column",{key:"9dcfc93f2f09eb6fa1892542e13a100015af79a4"},h("sc-input",{key:"8d7e7aa6283d33846754ed1ceb7440e092b86b06",label:__("First Name","surecart"),name:"first_name",value:null===(s=this.user)||void 0===s?void 0:s.first_name})),h("sc-column",{key:"c4b9439106b37d6efe311e73498f66c77d43ba87"},h("sc-input",{key:"c28492cf80de562e6ff1bfe214082f988f662c8a",label:__("Last Name","surecart"),name:"last_name",value:null===(a=this.user)||void 0===a?void 0:a.last_name}))),h("sc-input",{key:"6e9452110a8bfaa8a4eaf30baeaa84261643bfeb",label:__("Display Name","surecart"),name:"name",value:null===(t=this.user)||void 0===t?void 0:t.display_name}),h("div",{key:"a32f6a1a72b1491da99aa9dfdd2af470a8e0aa5f"},h("sc-button",{key:"04b889c2844159f03c9da35e88d8f0f776201ef1",type:"primary",full:!0,submit:!0},__("Save","surecart"))))),this.loading&&h("sc-block-ui",{key:"c4532c6c5190036149955417180b03f82e476de0",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:{}}}}