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 { d as defineCustomElement$e } from './sc-alert2.js';
import { d as defineCustomElement$d } from './sc-block-ui2.js';
import { d as defineCustomElement$c } from './sc-button2.js';
import { d as defineCustomElement$b } from './sc-card2.js';
import { d as defineCustomElement$a } from './sc-column2.js';
import { d as defineCustomElement$9 } from './sc-columns2.js';
import { d as defineCustomElement$8 } from './sc-dashboard-module2.js';
import { d as defineCustomElement$7 } from './sc-form2.js';
import { d as defineCustomElement$6 } from './sc-form-control2.js';
import { d as defineCustomElement$5 } from './sc-icon2.js';
import { d as defineCustomElement$4 } from './sc-input2.js';
import { d as defineCustomElement$3 } from './sc-spinner2.js';
import { d as defineCustomElement$2 } from './sc-tooltip2.js';

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

const ScWordPressUserEdit = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
  }
  renderEmpty() {
    return h("slot", { name: "empty" }, __('User not found.', 'surecart'));
  }
  async handleSubmit(e) {
    this.loading = true;
    try {
      const { email, first_name, last_name, name } = await e.target.getFormJson();
      await apiFetch({
        path: `wp/v2/users/me`,
        method: 'PATCH',
        data: {
          first_name,
          last_name,
          email,
          name,
        },
      });
      if (this.successUrl) {
        window.location.assign(this.successUrl);
      }
      else {
        this.loading = false;
      }
    }
    catch (e) {
      this.error = (e === null || e === void 0 ? void 0 : e.message) || __('Something went wrong', 'surecart');
      this.loading = false;
    }
  }
  render() {
    var _a, _b, _c, _d;
    return (h("sc-dashboard-module", { class: "account-details", error: this.error }, h("span", { slot: "heading" }, this.heading || __('Account Details', 'surecart'), " "), h("sc-card", null, h("sc-form", { onScFormSubmit: e => this.handleSubmit(e) }, h("sc-input", { label: __('Billing Email', 'surecart'), name: "email", value: (_a = this.user) === null || _a === void 0 ? void 0 : _a.email, required: true }), h("sc-columns", { style: { '--sc-column-spacing': 'var(--sc-spacing-medium)' } }, h("sc-column", null, h("sc-input", { label: __('First Name', 'surecart'), name: "first_name", value: (_b = this.user) === null || _b === void 0 ? void 0 : _b.first_name })), h("sc-column", null, h("sc-input", { label: __('Last Name', 'surecart'), name: "last_name", value: (_c = this.user) === null || _c === void 0 ? void 0 : _c.last_name }))), h("sc-input", { label: __('Display Name', 'surecart'), name: "name", value: (_d = this.user) === null || _d === void 0 ? void 0 : _d.display_name }), h("div", null, h("sc-button", { type: "primary", full: true, submit: true }, __('Save', 'surecart'))))), this.loading && h("sc-block-ui", { spinner: true })));
  }
  static get style() { return scWordpressUserEditCss; }
}, [1, "sc-wordpress-user-edit", {
    "heading": [1],
    "successUrl": [1, "success-url"],
    "user": [16],
    "loading": [32],
    "error": [32]
  }]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-wordpress-user-edit", "sc-alert", "sc-block-ui", "sc-button", "sc-card", "sc-column", "sc-columns", "sc-dashboard-module", "sc-form", "sc-form-control", "sc-icon", "sc-input", "sc-spinner", "sc-tooltip"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-wordpress-user-edit":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScWordPressUserEdit);
      }
      break;
    case "sc-alert":
      if (!customElements.get(tagName)) {
        defineCustomElement$e();
      }
      break;
    case "sc-block-ui":
      if (!customElements.get(tagName)) {
        defineCustomElement$d();
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "sc-card":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "sc-column":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sc-columns":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sc-dashboard-module":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-form":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-form-control":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-input":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-tooltip":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const ScWordpressUserEdit = ScWordPressUserEdit;
const defineCustomElement = defineCustomElement$1;

export { ScWordpressUserEdit, defineCustomElement };
