import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { _ as __ } from './default-i18n.js';
import './index2.js';
import { d as defineCustomElement$8 } from './sc-alert2.js';
import { d as defineCustomElement$7 } from './sc-block-ui2.js';
import { d as defineCustomElement$6 } from './sc-button2.js';
import { d as defineCustomElement$5 } from './sc-card2.js';
import { d as defineCustomElement$4 } from './sc-form2.js';
import { d as defineCustomElement$3 } from './sc-icon2.js';
import { d as defineCustomElement$2 } from './sc-spinner2.js';

const paymentMethodCreateCss = "sc-payment-method-create{display:block;position:relative}";

const ScPaymentMethodCreate$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.loading = false;
  }
  /**
   * Handle form submission.
   */
  async handleSubmit() {
    const element = this.el.querySelector('sc-stripe-payment-element');
    if (!element) {
      this.error = __('Something went wrong', 'surecart');
      return;
    }
    this.loading = true;
    try {
      await element.confirm('setup', {
        successUrl: this.successUrl,
      });
      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-card", null, h("sc-form", { onScFormSubmit: () => this.handleSubmit() }, this.error && (h("sc-alert", { open: !!this.error, type: "danger" }, h("span", { slot: "title" }, __('Error', 'surecart')), this.error)), h("slot", null), h("sc-button", { type: "primary", submit: true, full: true, loading: this.loading }, __('Save Payment Method', 'surecart')), this.loading && h("sc-block-ui", null))));
  }
  get el() { return this; }
  static get style() { return paymentMethodCreateCss; }
}, [4, "sc-payment-method-create", {
    "error": [1],
    "clientSecret": [1, "client-secret"],
    "successUrl": [1, "success-url"],
    "loading": [32]
  }]);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-payment-method-create", "sc-alert", "sc-block-ui", "sc-button", "sc-card", "sc-form", "sc-icon", "sc-spinner"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-payment-method-create":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScPaymentMethodCreate$1);
      }
      break;
    case "sc-alert":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-block-ui":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-card":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-form":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const ScPaymentMethodCreate = ScPaymentMethodCreate$1;
const defineCustomElement = defineCustomElement$1;

export { ScPaymentMethodCreate, defineCustomElement };
