import{h}from"@stencil/core";import{__}from"@wordpress/i18n";import{addQueryArgs}from"@wordpress/url";import apiFetch from"../../../../functions/fetch";import{onFirstVisible}from"../../../../functions/lazy";export class ScDashboardCustomerDetails{constructor(){this.customerId=void 0,this.heading=void 0,this.customer=void 0,this.loading=void 0,this.error=void 0}componentWillLoad(){onFirstVisible(this.el,(()=>{this.fetch()}))}async fetch(){if(""!==this.customerId)try{this.loading=!0,this.customer=await await apiFetch({path:addQueryArgs(`surecart/v1/customers/${this.customerId}`,{expand:["shipping_address","billing_address","tax_identifier"]})})}catch(t){(null==t?void 0:t.message)?this.error=t.message:this.error=__("Something went wrong","surecart"),console.error(this.error)}finally{this.loading=!1}}render(){return h("sc-customer-details",{key:"1896331a0ec0570d43006588d70ed8bfa9d85b99",customer:this.customer,loading:this.loading,error:this.error,heading:this.heading,"edit-link":addQueryArgs(window.location.href,{action:"edit",model:"customer",id:this.customerId})})}static get is(){return"sc-dashboard-customer-details"}static get encapsulation(){return"shadow"}static get originalStyleUrls(){return{$:["sc-dashboard-customer-details.css"]}}static get styleUrls(){return{$:["sc-dashboard-customer-details.css"]}}static get properties(){return{customerId:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"customer-id",reflect:!1},heading:{type:"string",mutable:!1,complexType:{original:"string",resolved:"string",references:{}},required:!1,optional:!1,docs:{tags:[],text:""},attribute:"heading",reflect:!1}}}static get states(){return{customer:{},loading:{},error:{}}}static get elementRef(){return"el"}}