import { r as registerInstance, h } from './index-f1d2a96f.js';
import { _ as __ } from './default-i18n-91ef32a0.js';
import './index-0a61debd.js';
import { a as apiFetch } from './fetch-c0c608db.js';
import './_commonjsHelpers-9943807e.js';
import './add-query-args-f4c5962b.js';

const scWordpressPasswordEditCss = ":host{display:block;position:relative}";

const ScWordPressPasswordEdit = class {
  constructor(hostRef) {
    registerInstance(this, hostRef);
  }
  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 })));
  }
};
ScWordPressPasswordEdit.style = scWordpressPasswordEditCss;

export { ScWordPressPasswordEdit as sc_wordpress_password_edit };
