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$c } from './sc-alert2.js';
import { d as defineCustomElement$b } from './sc-block-ui2.js';
import { d as defineCustomElement$a } from './sc-button2.js';
import { d as defineCustomElement$9 } from './sc-card2.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 scWordpressPasswordEditCss = ":host{display:block;position:relative}";

const ScWordPressPasswordEdit = /*@__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;
    this.error = '';
    try {
      const { password, password_confirm } = await e.target.getFormJson();
      if (password !== password_confirm) {
        throw { message: __('Passwords do not match.', 'surecart') };
      }
      await apiFetch({
        path: `wp/v2/users/me`,
        method: 'PATCH',
        data: {
          password,
        },
      });
      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() {
    return (h("sc-dashboard-module", { class: "customer-details", error: this.error }, h("span", { slot: "heading" }, this.heading || __('Update Password', 'surecart'), " "), h("sc-card", null, h("sc-form", { onScFormSubmit: e => this.handleSubmit(e) }, h("sc-input", { label: __('New Password', 'surecart'), name: "password", type: "password", required: true }), h("sc-input", { label: __('Confirm New Password', 'surecart'), name: "password_confirm", type: "password", required: true }), h("div", null, h("sc-button", { type: "primary", full: true, submit: true }, __('Update Password', 'surecart'))))), this.loading && h("sc-block-ui", { spinner: true })));
  }
  static get style() { return scWordpressPasswordEditCss; }
}, [1, "sc-wordpress-password-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-password-edit", "sc-alert", "sc-block-ui", "sc-button", "sc-card", "sc-dashboard-module", "sc-form", "sc-form-control", "sc-icon", "sc-input", "sc-spinner", "sc-tooltip"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-wordpress-password-edit":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScWordPressPasswordEdit);
      }
      break;
    case "sc-alert":
      if (!customElements.get(tagName)) {
        defineCustomElement$c();
      }
      break;
    case "sc-block-ui":
      if (!customElements.get(tagName)) {
        defineCustomElement$b();
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$a();
      }
      break;
    case "sc-card":
      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 ScWordpressPasswordEdit = ScWordPressPasswordEdit;
const defineCustomElement = defineCustomElement$1;

export { ScWordpressPasswordEdit, defineCustomElement };
