import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { _ as __ } from './default-i18n.js';
import './index2.js';
import { a as apiFetch } from './fetch.js';
import { o as onFirstVisible } from './lazy.js';
import { d as defineCustomElement$c } from './sc-alert2.js';
import { d as defineCustomElement$b } from './sc-button2.js';
import { d as defineCustomElement$a } from './sc-card2.js';
import { d as defineCustomElement$9 } from './sc-customer-details2.js';
import { d as defineCustomElement$8 } from './sc-dashboard-module2.js';
import { d as defineCustomElement$7 } from './sc-icon2.js';
import { d as defineCustomElement$6 } from './sc-skeleton2.js';
import { d as defineCustomElement$5 } from './sc-spinner2.js';
import { d as defineCustomElement$4 } from './sc-stacked-list2.js';
import { d as defineCustomElement$3 } from './sc-stacked-list-row2.js';
import { d as defineCustomElement$2 } from './sc-tag2.js';
import { a as addQueryArgs } from './add-query-args.js';

const scDashboardCustomerDetailsCss = ":host{display:block;position:relative}.customer-details{display:grid;gap:0.75em}";

const ScDashboardCustomerDetails$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
  }
  componentWillLoad() {
    onFirstVisible(this.el, () => {
      this.fetch();
    });
  }
  async fetch() {
    try {
      this.loading = true;
      this.customer = (await await apiFetch({
        path: addQueryArgs(`surecart/v1/customers/${this.customerId}`, {
          expand: ['shipping_address', 'billing_address', 'tax_identifier'],
        }),
      }));
    }
    catch (e) {
      if (e === null || e === void 0 ? void 0 : e.message) {
        this.error = e.message;
      }
      else {
        this.error = __('Something went wrong', 'surecart');
      }
      console.error(this.error);
    }
    finally {
      this.loading = false;
    }
  }
  render() {
    return (h("sc-customer-details", { customer: this.customer, loading: this.loading, error: this.error, "edit-link": addQueryArgs(window.location.href, {
        action: 'edit',
        model: 'customer',
        id: this.customerId,
      }) }));
  }
  get el() { return this; }
  static get style() { return scDashboardCustomerDetailsCss; }
}, [1, "sc-dashboard-customer-details", {
    "customerId": [1, "customer-id"],
    "heading": [1],
    "customer": [32],
    "loading": [32],
    "error": [32]
  }]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-dashboard-customer-details", "sc-alert", "sc-button", "sc-card", "sc-customer-details", "sc-dashboard-module", "sc-icon", "sc-skeleton", "sc-spinner", "sc-stacked-list", "sc-stacked-list-row", "sc-tag"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-dashboard-customer-details":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScDashboardCustomerDetails$1);
      }
      break;
    case "sc-alert":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "sc-card":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sc-customer-details":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sc-dashboard-module":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-skeleton":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-stacked-list":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sc-stacked-list-row":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-tag":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const ScDashboardCustomerDetails = ScDashboardCustomerDetails$1;
const defineCustomElement = defineCustomElement$1;

export { ScDashboardCustomerDetails, defineCustomElement };
