import { proxyCustomElement, HTMLElement } from '@stencil/core/internal/client';
import { _ as __ } from './default-i18n.js';
import './index2.js';

const ScCheckoutUnsavedChangesWarning = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    this.__attachShadow();
  }
  /**
   * Add event listener for beforeunload.
   */
  componentDidLoad() {
    window.addEventListener('beforeunload', e => this.warnIfUnsavedChanges(e), { capture: true });
  }
  /**
   * Warn if status is updaing, finalizing, paying or confirming.
   */
  warnIfUnsavedChanges(e) {
    if (['updating', 'finalizing', 'confirming'].includes(this.state)) {
      console.log({ e });
      e.preventDefault();
      e.returnValue = __('Your payment is processing. Exiting this page could cause an error in your order. Please do not navigate away from this page.', 'surecart');
      return e.returnValue;
    }
  }
}, [1, "sc-checkout-unsaved-changes-warning", {
    "state": [1]
  }]);
function defineCustomElement() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-checkout-unsaved-changes-warning"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-checkout-unsaved-changes-warning":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScCheckoutUnsavedChangesWarning);
      }
      break;
  } });
}
defineCustomElement();

export { ScCheckoutUnsavedChangesWarning as S, defineCustomElement as d };
