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:"1f6cfbc93e7bb5c58c80b3b7a6eb13d62e34f011",class:"account-details",error:this.error},h("span",{key:"25d26787f7d4320d4cc744fb148e4460e7d51abe",slot:"heading"},this.heading||__("Account Details","surecart")," "),h("sc-card",{key:"5fa8f5e57de593d5414dbddb561253df231d9439"},h("sc-form",{key:"4734b933a755d483cd95384b3fb5ba897a9cda99",onScFormSubmit:e=>this.handleSubmit(e)},h("sc-input",{key:"26fbf283b159ac9474ec054f24b845572c6dc3da",label:__("Account Email","surecart"),name:"email",value:null===(e=this.user)||void 0===e?void 0:e.email,required:!0}),h("sc-columns",{key:"5aca9b4439fe3d10c56f99ad563b4c7cefd254c5",style:{"--sc-column-spacing":"var(--sc-spacing-medium)"}},h("sc-column",{key:"6eae1eb38b0b074549c212bc7f0555c1062defaf"},h("sc-input",{key:"5e3c72b495dfd0d35e78e915de3621153d7705e0",label:__("First Name","surecart"),name:"first_name",value:null===(s=this.user)||void 0===s?void 0:s.first_name})),h("sc-column",{key:"9b879810c5b44b89128f8cdf75122bab504f163f"},h("sc-input",{key:"94b792dc95ee084e3729e70bbf56e7f7ffec3ed6",label:__("Last Name","surecart"),name:"last_name",value:null===(t=this.user)||void 0===t?void 0:t.last_name}))),h("sc-input",{key:"411e12095633a8bcddbd488955dde76c5f96629e",label:__("Display Name","surecart"),name:"name",value:null===(r=this.user)||void 0===r?void 0:r.display_name}),h("div",{key:"5d2801d4f0ae73061fd385714812d6d5f986625b"},h("sc-button",{key:"505a95009635ebaab9140df81d0d2468fc163237",type:"primary",full:!0,submit:!0},__("Save","surecart"))))),this.loading&&h("sc-block-ui",{key:"416d6da7d09e1baeeb81b1c3602cc8a61aa8ddde",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:{}}}}