import { r as registerInstance, h, g as getElement } from './index-f1d2a96f.js';
import { _ as __ } from './default-i18n-91ef32a0.js';
import './index-0a61debd.js';
import './_commonjsHelpers-9943807e.js';

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

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

export { ScPaymentMethodCreate as sc_payment_method_create };
