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:"63b10a42189403935ed2d149f6432b7c215b5411",class:"account-details",error:this.error},h("span",{key:"0a2f72f909d54fafafb40db7e07ab8c1d8e9f642",slot:"heading"},this.heading||__("Account Details","surecart")," "),h("sc-card",{key:"43a45982cf08116e2a46be04b0d210719e467200"},h("sc-form",{key:"80cc9132b372b9a3523b13a506040061e9d59a7c",onScFormSubmit:e=>this.handleSubmit(e)},h("sc-input",{key:"0ffee3c9051bae7d5693c315a829132f273c752b",label:__("Account Email","surecart"),name:"email",value:null===(e=this.user)||void 0===e?void 0:e.email,required:!0}),h("sc-columns",{key:"807cdcf2de0971480f39d59b97aef3f06a35500e",style:{"--sc-column-spacing":"var(--sc-spacing-medium)"}},h("sc-column",{key:"598ff340ee9c3b4a8a08519e2c1604f1b8fd34d7"},h("sc-input",{key:"846b10eb01fed727e6640b1759bdd0e41866d555",label:__("First Name","surecart"),name:"first_name",value:null===(s=this.user)||void 0===s?void 0:s.first_name})),h("sc-column",{key:"de088f871fd1dab740212dffa36207a033b564b8"},h("sc-input",{key:"19783e82994bd63868e6881c09ac3a18490193d2",label:__("Last Name","surecart"),name:"last_name",value:null===(t=this.user)||void 0===t?void 0:t.last_name}))),h("sc-input",{key:"6816098890f6ffae8a32f1c330cf7446b15da828",label:__("Display Name","surecart"),name:"name",value:null===(r=this.user)||void 0===r?void 0:r.display_name}),h("div",{key:"4fccddd3a12d41cdaa6d407dee0fbc109a4c62eb"},h("sc-button",{key:"4bd7fea0b6fb5cd1a3ba7eb3760ee1fe48051fee",type:"primary",full:!0,submit:!0},__("Save","surecart"))))),this.loading&&h("sc-block-ui",{key:"643c26d7c3e844769fcbf992cf4d37ba769ff4e3",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:{}}}}