import { Component, Fragment, h, Prop } from '@stencil/core';
import { checkoutIsLocked } from '@store/checkout/getters';
import { availableProcessors } from '@store/processors/getters';
import { state as selectedProcessor } from '@store/selected-processor';
import { __ } from '@wordpress/i18n';
import { openWormhole } from 'stencil-wormhole';
import { getProcessorData } from '../../../../functions/processor';
export class ScOrderSubmit {
  constructor() {
    /** 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,
      selectedProcessor.id === 'paypal' && !(selectedProcessor === null || selectedProcessor === void 0 ? void 0 : selectedProcessor.method) && this.renderPayPalButton(['paypal']),
      selectedProcessor.id === 'paypal' && (selectedProcessor === null || selectedProcessor === void 0 ? void 0 : selectedProcessor.method) === 'card' && this.renderPayPalButton(['card']),
      h("sc-button", { hidden: ['paypal', 'paypal-card'].includes(selectedProcessor.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 is() { return "sc-order-submit"; }
  static get originalStyleUrls() { return {
    "$": ["sc-order-submit.scss"]
  }; }
  static get styleUrls() { return {
    "$": ["sc-order-submit.css"]
  }; }
  static get properties() { return {
    "busy": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Is the order busy"
      },
      "attribute": "busy",
      "reflect": false
    },
    "loading": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Is the order loading."
      },
      "attribute": "loading",
      "reflect": false
    },
    "paying": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Is the order paying."
      },
      "attribute": "paying",
      "reflect": false
    },
    "type": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'default' | 'primary' | 'success' | 'info' | 'warning' | 'danger' | 'text' | 'link'",
        "resolved": "\"danger\" | \"default\" | \"info\" | \"link\" | \"primary\" | \"success\" | \"text\" | \"warning\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The button type."
      },
      "attribute": "type",
      "reflect": true,
      "defaultValue": "'primary'"
    },
    "size": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'small' | 'medium' | 'large'",
        "resolved": "\"large\" | \"medium\" | \"small\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The button's size."
      },
      "attribute": "size",
      "reflect": true,
      "defaultValue": "'medium'"
    },
    "full": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Show a full-width button."
      },
      "attribute": "full",
      "reflect": false,
      "defaultValue": "true"
    },
    "icon": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Icon to show."
      },
      "attribute": "icon",
      "reflect": false
    },
    "showTotal": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Show the total."
      },
      "attribute": "show-total",
      "reflect": false
    },
    "mode": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "'test' | 'live'",
        "resolved": "\"live\" | \"test\"",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Is this created in \"test\" mode"
      },
      "attribute": "mode",
      "reflect": false,
      "defaultValue": "'live'"
    },
    "processors": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Processor[]",
        "resolved": "Processor[]",
        "references": {
          "Processor": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Keys and secrets for processors."
      }
    },
    "order": {
      "type": "unknown",
      "mutable": false,
      "complexType": {
        "original": "Checkout",
        "resolved": "Checkout",
        "references": {
          "Checkout": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The current order."
      }
    },
    "currencyCode": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Currency Code"
      },
      "attribute": "currency-code",
      "reflect": false,
      "defaultValue": "'usd'"
    },
    "processor": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "ProcessorName",
        "resolved": "\"paypal\" | \"paypal-card\" | \"stripe\"",
        "references": {
          "ProcessorName": {
            "location": "import",
            "path": "../../../../types"
          }
        }
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "The selected processor."
      },
      "attribute": "processor",
      "reflect": false
    },
    "secureNoticeText": {
      "type": "string",
      "mutable": false,
      "complexType": {
        "original": "string",
        "resolved": "string",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Secure"
      },
      "attribute": "secure-notice-text",
      "reflect": false
    },
    "secureNotice": {
      "type": "boolean",
      "mutable": false,
      "complexType": {
        "original": "boolean",
        "resolved": "boolean",
        "references": {}
      },
      "required": false,
      "optional": false,
      "docs": {
        "tags": [],
        "text": "Show the secure notice"
      },
      "attribute": "secure-notice",
      "reflect": false,
      "defaultValue": "true"
    }
  }; }
}
openWormhole(ScOrderSubmit, ['busy', 'loading', 'paying', 'processors', 'processor', 'mode', 'currencyCode', 'order'], false);
