'use strict';

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

const index = require('./index-9c866aeb.js');
const getters$1 = require('./getters-6c916233.js');
const getters = require('./getters-24bb377c.js');
const watchers = require('./watchers-d5742848.js');
const defaultI18n = require('./default-i18n-d4248548.js');
require('./index-88baf240.js');
const consumer = require('./consumer-3f5ce850.js');
require('./watchers-203d7acd.js');
require('./index-f6f80680.js');
require('./add-query-args-17c551b6.js');
require('./util-872b1a55.js');
require('./index-04dc658f.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 = class {
  constructor(hostRef) {
    index.registerInstance(this, hostRef);
    /** 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(getters.availableProcessors(), 'paypal', this.mode);
    if (!client_id && !account_id)
      return null;
    return (index.h("sc-paypal-buttons", { buttons: buttons, busy: this.busy || getters$1.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 (index.h(index.Fragment, null, watchers.state.id === 'paypal' && !(watchers.state === null || watchers.state === void 0 ? void 0 : watchers.state.method) && this.renderPayPalButton(['paypal']), watchers.state.id === 'paypal' && (watchers.state === null || watchers.state === void 0 ? void 0 : watchers.state.method) === 'card' && this.renderPayPalButton(['card']), index.h("sc-button", { hidden: ['paypal', 'paypal-card'].includes(watchers.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 || getters$1.checkoutIsLocked() }, !!this.icon && index.h("sc-icon", { name: this.icon, slot: "prefix" }), index.h("slot", null, defaultI18n.__('Purchase', 'surecart')), this.showTotal && (index.h("span", null, '\u00A0', index.h("sc-total", null)))), this.secureNotice && location.protocol === 'https:' && (index.h("div", { class: "sc-secure-notice" }, index.h("sc-secure-notice", null, this.secureNoticeText || defaultI18n.__('This is a secure, encrypted payment.', 'surecart'))))));
  }
};
consumer.openWormhole(ScOrderSubmit, ['busy', 'loading', 'paying', 'processors', 'processor', 'mode', 'currencyCode', 'order'], false);
ScOrderSubmit.style = scOrderSubmitCss;

exports.sc_order_submit = ScOrderSubmit;
