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:"918c492a9335adf99ccf9834d0c3174564e8e658",class:"account-details",error:this.error},h("span",{key:"999100523f1572b7b85f4fd3700a05e0ea4702fd",slot:"heading"},this.heading||__("Account Details","surecart")," "),h("sc-card",{key:"d12350fd46621b21ba8c1aa1bac28efcb95a8de8"},h("sc-form",{key:"0b103ca1f3ac2f17f25c9d0017f288cb099de691",onScFormSubmit:e=>this.handleSubmit(e)},h("sc-input",{key:"e927f1a6b1006c3adba75ce5b9549c3e635b758a",label:__("Account Email","surecart"),name:"email",value:null===(e=this.user)||void 0===e?void 0:e.email,required:!0}),h("sc-columns",{key:"47fe57acf5f32fc63703d2e92af3c59773ffdc63",style:{"--sc-column-spacing":"var(--sc-spacing-medium)"}},h("sc-column",{key:"ed1f9cf1dd749df4655aa6b695d287caf4f7d86a"},h("sc-input",{key:"52407f9274b55e09a080882db12621500345fe57",label:__("First Name","surecart"),name:"first_name",value:null===(s=this.user)||void 0===s?void 0:s.first_name})),h("sc-column",{key:"47d2c630a2ae7508f96bc015a9c5281494f536da"},h("sc-input",{key:"625f6eff33684a33501842de3766990c06036633",label:__("Last Name","surecart"),name:"last_name",value:null===(a=this.user)||void 0===a?void 0:a.last_name}))),h("sc-input",{key:"4f595a954e056e7afe4a0691ae0bdb43ac6a6aba",label:__("Display Name","surecart"),name:"name",value:null===(t=this.user)||void 0===t?void 0:t.display_name}),h("div",{key:"aaf42bbaf4d158be639d2214049dd5861f000a07"},h("sc-button",{key:"0af1ea77c02f014f818414f7e20f7afa940c518e",type:"primary",full:!0,submit:!0},__("Save","surecart"))))),this.loading&&h("sc-block-ui",{key:"f49b0aa8cc69ea4836db7cc0876307ba530219f8",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:{}}}}