'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

const index = require('./index-cd6fab62.js');
const defaultI18n = require('./default-i18n-072e75d7.js');
require('./index-20b57ec7.js');
require('./_commonjsHelpers-537d719a.js');

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

const ScPaymentMethodCreate = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    this.loading = false;
  }
  /**
   * Handle form submission.
   */
  async handleSubmit() {
    const element = this.el.querySelector('sc-stripe-payment-element');
    if (!element) {
      this.error = defaultI18n.__('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) || defaultI18n.__('Something went wrong', 'surecart');
      this.loading = false;
    }
  }
  render() {
    return (index.h("sc-card", null, index.h("sc-form", { onScFormSubmit: () => this.handleSubmit() }, this.error && (index.h("sc-alert", { open: !!this.error, type: "danger" }, index.h("span", { slot: "title" }, defaultI18n.__('Error', 'surecart')), this.error)), index.h("slot", null), index.h("sc-button", { type: "primary", submit: true, full: true, loading: this.loading }, defaultI18n.__('Save Payment Method', 'surecart')), this.loading && index.h("sc-block-ui", null))));
  }
  get el() { return index.getElement(this); }
};
ScPaymentMethodCreate.style = paymentMethodCreateCss;

exports.sc_payment_method_create = ScPaymentMethodCreate;
