import { proxyCustomElement, HTMLElement, h, Fragment } from '@stencil/core/internal/client';
import { a as checkoutIsLocked } from './getters2.js';
import { a as availableProcessors } from './getters.js';
import { s as state } from './watchers3.js';
import { _ as __ } from './default-i18n.js';
import './index2.js';
import { o as openWormhole } from './consumer.js';
import { d as defineCustomElement$9 } from './sc-button2.js';
import { d as defineCustomElement$8 } from './sc-format-number2.js';
import { d as defineCustomElement$7 } from './sc-icon2.js';
import { d as defineCustomElement$6 } from './paypal-buttons.js';
import { d as defineCustomElement$5 } from './sc-secure-notice2.js';
import { d as defineCustomElement$4 } from './sc-skeleton2.js';
import { d as defineCustomElement$3 } from './sc-spinner2.js';
import { d as defineCustomElement$2 } from './sc-total2.js';

const getProcessorData = (processors = [], type, mode) => {
  var _a;
  return ((_a = (processors || []).find(processor => (processor === null || processor === void 0 ? void 0 : processor.processor_type) === type && (processor === null || processor === void 0 ? void 0 : processor.live_mode) === !!(mode === 'live'))) === null || _a === void 0 ? void 0 : _a.processor_data) || {};
};

const scOrderSubmitCss = "sc-order-submit{display:block;width:auto;display:grid;gap:var(--sc-form-row-spacing)}.sc-secure-notice{display:flex;justify-content:center}";

const ScOrderSubmit$1 = /*@__PURE__*/ proxyCustomElement(class extends HTMLElement {
  constructor() {
    super();
    this.__registerHost();
    /** The button type. */
    this.type = 'primary';
    /** The button's size. */
    this.size = 'medium';
    /** Show a full-width button. */
    this.full = true;
    /** Is this created in "test" mode */
    this.mode = 'live';
    /** Currency Code */
    this.currencyCode = 'usd';
    /** Show the secure notice */
    this.secureNotice = true;
  }
  renderPayPalButton(buttons) {
    const { client_id, account_id, merchant_initiated_enabled } = getProcessorData(availableProcessors(), 'paypal', this.mode);
    if (!client_id && !account_id)
      return null;
    return (h("sc-paypal-buttons", { buttons: buttons, busy: this.busy || checkoutIsLocked(), mode: this.mode, order: this.order, merchantInitiated: merchant_initiated_enabled, "currency-code": this.currencyCode, "client-id": client_id, "merchant-id": account_id, label: "checkout", color: "blue" }));
  }
  render() {
    return (h(Fragment, null, state.id === 'paypal' && !(state === null || state === void 0 ? void 0 : state.method) && this.renderPayPalButton(['paypal']), state.id === 'paypal' && (state === null || state === void 0 ? void 0 : state.method) === 'card' && this.renderPayPalButton(['card']), h("sc-button", { hidden: ['paypal', 'paypal-card'].includes(state.id), submit: true, type: this.type, size: this.size, full: this.full, loading: this.loading || this.paying, disabled: this.loading || this.paying || this.busy || checkoutIsLocked() }, !!this.icon && h("sc-icon", { name: this.icon, slot: "prefix" }), h("slot", null, __('Purchase', 'surecart')), this.showTotal && (h("span", null, '\u00A0', h("sc-total", null)))), this.secureNotice && location.protocol === 'https:' && (h("div", { class: "sc-secure-notice" }, h("sc-secure-notice", null, this.secureNoticeText || __('This is a secure, encrypted payment.', 'surecart'))))));
  }
  static get style() { return scOrderSubmitCss; }
}, [4, "sc-order-submit", {
    "busy": [4],
    "loading": [4],
    "paying": [4],
    "type": [513],
    "size": [513],
    "full": [4],
    "icon": [1],
    "showTotal": [4, "show-total"],
    "mode": [1],
    "processors": [16],
    "order": [16],
    "currencyCode": [1, "currency-code"],
    "processor": [1],
    "secureNoticeText": [1, "secure-notice-text"],
    "secureNotice": [4, "secure-notice"]
  }]);
openWormhole(ScOrderSubmit$1, ['busy', 'loading', 'paying', 'processors', 'processor', 'mode', 'currencyCode', 'order'], false);
function defineCustomElement$1() {
  if (typeof customElements === "undefined") {
    return;
  }
  const components = ["sc-order-submit", "sc-button", "sc-format-number", "sc-icon", "sc-paypal-buttons", "sc-secure-notice", "sc-skeleton", "sc-spinner", "sc-total"];
  components.forEach(tagName => { switch (tagName) {
    case "sc-order-submit":
      if (!customElements.get(tagName)) {
        customElements.define(tagName, ScOrderSubmit$1);
      }
      break;
    case "sc-button":
      if (!customElements.get(tagName)) {
        defineCustomElement$9();
      }
      break;
    case "sc-format-number":
      if (!customElements.get(tagName)) {
        defineCustomElement$8();
      }
      break;
    case "sc-icon":
      if (!customElements.get(tagName)) {
        defineCustomElement$7();
      }
      break;
    case "sc-paypal-buttons":
      if (!customElements.get(tagName)) {
        defineCustomElement$6();
      }
      break;
    case "sc-secure-notice":
      if (!customElements.get(tagName)) {
        defineCustomElement$5();
      }
      break;
    case "sc-skeleton":
      if (!customElements.get(tagName)) {
        defineCustomElement$4();
      }
      break;
    case "sc-spinner":
      if (!customElements.get(tagName)) {
        defineCustomElement$3();
      }
      break;
    case "sc-total":
      if (!customElements.get(tagName)) {
        defineCustomElement$2();
      }
      break;
  } });
}
defineCustomElement$1();

const ScOrderSubmit = ScOrderSubmit$1;
const defineCustomElement = defineCustomElement$1;

export { ScOrderSubmit, defineCustomElement };
