import { proxyCustomElement, HTMLElement, createEvent, h } from '@stencil/core/internal/client';
import { J as JustifiAnalytics } from './Analytics.js';
import { c as checkPkgVersion } from './check-pkg-version.js';
import { c as checkoutStore } from './checkout.store.js';
import { ac as checkoutSummary } from './parts.js';
import { S as StyledHost } from './styled-host.js';
import './justifi-details2.js';
import './event-types.js';
import { d as defineCustomElement$7 } from './justifi-radio-list-item2.js';
import { P as PAYMENT_METHODS } from './ModularCheckout.js';
import { d as defineCustomElement$u } from './bank-account-billing-form-simple2.js';
import { d as defineCustomElement$t } from './bank-account-form2.js';
import { d as defineCustomElement$s } from './billing-form2.js';
import { d as defineCustomElement$r } from './billing-form-full2.js';
import { d as defineCustomElement$q } from './card-billing-form-simple2.js';
import { d as defineCustomElement$p } from './card-form2.js';
import { d as defineCustomElement$o } from './custom-popper2.js';
import { d as defineCustomElement$n } from './form-control-checkbox2.js';
import { d as defineCustomElement$m } from './form-control-help-text3.js';
import { d as defineCustomElement$l } from './form-control-radio2.js';
import { d as defineCustomElement$k } from './form-control-select2.js';
import { d as defineCustomElement$j } from './form-control-text2.js';
import { d as defineCustomElement$i } from './form-control-tooltip2.js';
import { d as defineCustomElement$h } from './hidden-input2.js';
import { d as defineCustomElement$g } from './iframe-input2.js';
import { d as defineCustomElement$f } from './internal-button2.js';
import { d as defineCustomElement$e } from './justifi-apple-pay2.js';
import { d as defineCustomElement$d } from './justifi-button2.js';
import { d as defineCustomElement$c } from './justifi-checkout-summary2.js';
import { d as defineCustomElement$b } from './justifi-google-pay2.js';
import { d as defineCustomElement$a } from './justifi-header2.js';
import { d as defineCustomElement$9 } from './justifi-modular-checkout2.js';
import { d as defineCustomElement$8 } from './justifi-plaid-payment-method2.js';
import { d as defineCustomElement$6 } from './justifi-saved-payment-methods2.js';
import { d as defineCustomElement$5 } from './justifi-sezzle-payment-method2.js';
import { d as defineCustomElement$4 } from './justifi-tokenize-payment-method2.js';
import { d as defineCustomElement$3 } from './radio-list-item2.js';
import { d as defineCustomElement$2 } from './save-new-payment-method2.js';

const JustifiCheckout$1 = /*@__PURE__*/ proxyCustomElement(class JustifiCheckout extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.errorEvent = createEvent(this, "error-event", 7);
        this.loadedEvent = createEvent(this, "loaded", 7);
        this.submitEvent = createEvent(this, "submit-event", 7);
        this.availablePaymentMethods = [];
        this.errorMessage = '';
        this.insuranceToggled = false;
        this.disableBankAccount = false;
        this.disableBnpl = false;
        this.disableCreditCard = false;
        this.disablePaymentMethodGroup = false;
        this.hideBankAccountBillingForm = false;
        this.hideCardBillingForm = false;
    }
    propChanged() {
        this.updateStore();
    }
    connectedCallback() {
        if (this.authToken && this.checkoutId) {
            this.updateStore();
        }
    }
    componentWillLoad() {
        checkPkgVersion();
        this.analytics = new JustifiAnalytics(this);
    }
    disconnectedCallback() {
        var _a;
        (_a = this.analytics) === null || _a === void 0 ? void 0 : _a.cleanup();
    }
    checkoutComplete(_event) {
        checkoutStore.isSubmitting = false;
    }
    checkoutError(_event) {
        checkoutStore.isSubmitting = false;
    }
    checkoutChanged(event) {
        // if disabled bnpl, remove sezzle from available payment methods
        if (this.disableBnpl) {
            this.availablePaymentMethods = event.detail.availablePaymentMethodTypes.filter((method) => method !== PAYMENT_METHODS.SEZZLE);
            return;
        }
        this.availablePaymentMethods = event.detail.availablePaymentMethodTypes;
    }
    async fillBillingForm(fields) {
        checkoutStore.billingFormFields = fields;
    }
    async validate() {
        var _a;
        const modularValidation = await ((_a = this.modularCheckoutRef) === null || _a === void 0 ? void 0 : _a.validate());
        return { isValid: modularValidation };
    }
    updateStore() {
        checkoutStore.checkoutId = this.checkoutId;
        checkoutStore.authToken = this.authToken;
        checkoutStore.disableCreditCard = this.disableCreditCard;
        checkoutStore.disableBankAccount = this.disableBankAccount;
        checkoutStore.disablePaymentMethodGroup = this.disablePaymentMethodGroup;
    }
    async submit(_event) {
        var _a;
        (_a = this.modularCheckoutRef) === null || _a === void 0 ? void 0 : _a.submitCheckout(checkoutStore.billingFormFields);
    }
    get showPaymentTypeHeader() {
        return !this.disableCreditCard && !this.disableBankAccount;
    }
    render() {
        var _a, _b;
        return (h(StyledHost, { key: 'bc8428227b2fc0e0753c4ef4e2370cd34bd34e82' }, h("justifi-modular-checkout", { key: '9fda18728d6fb5b20716070cefc2fcf8ef097459', ref: (el) => {
                this.modularCheckoutRef = el;
            }, authToken: this.authToken, checkoutId: this.checkoutId, preCompleteHook: this.preCompleteHook }, h("div", { key: 'e39f9871696d44cea2080198c7b91d03b706f2fd', class: "row gy-3 jfi-checkout-core" }, h("div", { key: 'df6045e9394b10f9b3e4b86e1a2242db30cc9b7b', class: "col-12", part: checkoutSummary }, h("justifi-header", { key: '8f4332bd43371106faf4e264fd5b27c97cb589aa', text: "Summary", level: "h2", class: "fs-5 fw-bold pb-3" }), h("section", { key: 'a7170276f18b9fa4b085c4d5de35979d55935929' }, h("justifi-checkout-summary", { key: '109aceb53ad2500e927230b3f82bbb07ab3f604c' }))), h("div", { key: '902e040bbd591408c9d292a592ca4d31fc838d85', class: "col-12 mt-4" }, h("slot", { key: '2677cb4952d88a8ce8f0198b96ed2638d4f4e6eb', name: "insurance" })), h("div", { key: '32c033bba12a7b7bf26159bd1878d6fa4ed913d9', class: "col-12 mt-4" }, h("justifi-header", { key: '74543b63c1b94a5200ad36236818fce7345d5d76', text: "Payment", level: "h2", class: "fs-5 fw-bold pb-3" }), this.showPaymentTypeHeader && (h("justifi-header", { key: '8e7c56c75bb779211b72c0b8561df8283b731ca1', text: "Select payment type", level: "h3", class: "fs-6 fw-bold lh-lg" })), h("div", { key: 'c2b0a875169b46dcd7d73428e3f1a4825b380ce5', class: "d-flex flex-column" }, h("section", { key: 'c5f007674c058e88d271c17f0b6b9c959bd0e044' }, h("div", { key: '2c4ecdd0f8708f9f80bae50362ba7fab295f788f' }, this.availablePaymentMethods.includes(PAYMENT_METHODS.APPLE_PAY) && (h("div", { key: '5ac363a3b7c38cb3f10e9c2c7916825f0f5dc2d8', class: "mb-3" }, h("justifi-apple-pay", { key: '498c03630e4057b54ebd12a3cd87b6b6bdb00c4b' }))), this.availablePaymentMethods.includes(PAYMENT_METHODS.GOOGLE_PAY) && (h("div", { key: '8c8114d142927739a3217d3a0a44c34c89e58f83', class: "mb-3" }, h("justifi-google-pay", Object.assign({ key: 'a2fbc5b99a83fbc52698422d2f57a3380f97733f', ref: (el) => (this.googlePayRef = el) }, (this.googlePayEnv != null ? { environment: this.googlePayEnv } : {}))))), h("justifi-saved-payment-methods", { key: '2e5b27eea7ef433e950feadae0b0a07f8b613533' }), this.availablePaymentMethods.includes(PAYMENT_METHODS.SEZZLE) && (h("justifi-radio-list-item", { key: 'fb1501c51eaf836579547bc50c295ebb67cb09c1', name: "paymentMethodType", value: PAYMENT_METHODS.SEZZLE, checked: ((_a = checkoutStore === null || checkoutStore === void 0 ? void 0 : checkoutStore.selectedPaymentMethod) === null || _a === void 0 ? void 0 : _a.type) === PAYMENT_METHODS.SEZZLE, label: h("justifi-sezzle-payment-method", { ref: (el) => (this.sezzlePaymentMethodRef = el) }), "onRadio-click": () => { var _a; (_a = this.sezzlePaymentMethodRef) === null || _a === void 0 ? void 0 : _a.handleSelectionClick(); } })), this.availablePaymentMethods.includes(PAYMENT_METHODS.PLAID) && !this.disableBnpl && (h("justifi-radio-list-item", { key: '49e0687b4955fb92935783250540fe38350bbdcc', name: "paymentMethodType", value: PAYMENT_METHODS.PLAID, checked: ((_b = checkoutStore === null || checkoutStore === void 0 ? void 0 : checkoutStore.selectedPaymentMethod) === null || _b === void 0 ? void 0 : _b.type) === PAYMENT_METHODS.PLAID, label: h("justifi-plaid-payment-method", { ref: (el) => (this.plaidPaymentMethodRef = el) }), "onRadio-click": () => { var _a; (_a = this.plaidPaymentMethodRef) === null || _a === void 0 ? void 0 : _a.handleSelectionClick(); } })), h("justifi-tokenize-payment-method", { key: 'ba793274de073c8a60c063e9caedcf32780b4bbf', ref: (el) => (this.tokenizePaymentMethodRef = el), authToken: this.authToken, accountId: checkoutStore.accountId, disableCreditCard: this.disableCreditCard, disableBankAccount: this.disableBankAccount, hideCardBillingForm: this.hideCardBillingForm, hideBankAccountBillingForm: this.hideBankAccountBillingForm, hideSubmitButton: true, paymentMethodGroupId: checkoutStore.paymentMethodGroupId }))))), h("div", { key: 'ed7be422c4e369382fd42e0b0162357df7de2031', class: "mt-4" }, h("justifi-button", { key: '849d648feec5ce805d6eb87acacf94d62e7a8f1b', text: "Pay", type: "submit", variant: "primary", clickHandler: (e) => this.submit(e), disabled: checkoutStore.isSubmitting || checkoutStore.isWalletProcessing, isLoading: checkoutStore.isSubmitting || checkoutStore.isWalletProcessing, customStyle: { width: '100%', textAlign: "center" } }))))));
    }
    static get watchers() { return {
        "authToken": ["propChanged"],
        "checkoutId": ["propChanged"],
        "disableCreditCard": ["propChanged"],
        "disableBankAccount": ["propChanged"],
        "disablePaymentMethodGroup": ["propChanged"]
    }; }
}, [260, "justifi-checkout", {
        "authToken": [1, "auth-token"],
        "checkoutId": [1, "checkout-id"],
        "disableBankAccount": [4, "disable-bank-account"],
        "disableBnpl": [4, "disable-bnpl"],
        "disableCreditCard": [4, "disable-credit-card"],
        "disablePaymentMethodGroup": [4, "disable-payment-method-group"],
        "hideBankAccountBillingForm": [4, "hide-bank-account-billing-form"],
        "hideCardBillingForm": [4, "hide-card-billing-form"],
        "googlePayEnv": [1, "google-pay-env"],
        "preCompleteHook": [16],
        "availablePaymentMethods": [32],
        "checkout": [32],
        "complete": [32],
        "errorMessage": [32],
        "insuranceToggled": [32],
        "serverError": [32],
        "fillBillingForm": [64],
        "validate": [64]
    }, [[0, "submit-event", "checkoutComplete"], [0, "error-event", "checkoutError"], [0, "checkout-changed", "checkoutChanged"]], {
        "authToken": ["propChanged"],
        "checkoutId": ["propChanged"],
        "disableCreditCard": ["propChanged"],
        "disableBankAccount": ["propChanged"],
        "disablePaymentMethodGroup": ["propChanged"]
    }]);
function defineCustomElement$1() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["justifi-checkout", "bank-account-billing-form-simple", "bank-account-form", "billing-form", "billing-form-full", "card-billing-form-simple", "card-form", "custom-popper", "form-control-checkbox", "form-control-help-text", "form-control-radio", "form-control-select", "form-control-text", "form-control-tooltip", "hidden-input", "iframe-input", "internal-button", "justifi-apple-pay", "justifi-button", "justifi-checkout-summary", "justifi-google-pay", "justifi-header", "justifi-modular-checkout", "justifi-plaid-payment-method", "justifi-radio-list-item", "justifi-saved-payment-methods", "justifi-sezzle-payment-method", "justifi-tokenize-payment-method", "radio-list-item", "save-new-payment-method"];
    components.forEach(tagName => { switch (tagName) {
        case "justifi-checkout":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, JustifiCheckout$1);
            }
            break;
        case "bank-account-billing-form-simple":
            if (!customElements.get(tagName)) {
                defineCustomElement$u();
            }
            break;
        case "bank-account-form":
            if (!customElements.get(tagName)) {
                defineCustomElement$t();
            }
            break;
        case "billing-form":
            if (!customElements.get(tagName)) {
                defineCustomElement$s();
            }
            break;
        case "billing-form-full":
            if (!customElements.get(tagName)) {
                defineCustomElement$r();
            }
            break;
        case "card-billing-form-simple":
            if (!customElements.get(tagName)) {
                defineCustomElement$q();
            }
            break;
        case "card-form":
            if (!customElements.get(tagName)) {
                defineCustomElement$p();
            }
            break;
        case "custom-popper":
            if (!customElements.get(tagName)) {
                defineCustomElement$o();
            }
            break;
        case "form-control-checkbox":
            if (!customElements.get(tagName)) {
                defineCustomElement$n();
            }
            break;
        case "form-control-help-text":
            if (!customElements.get(tagName)) {
                defineCustomElement$m();
            }
            break;
        case "form-control-radio":
            if (!customElements.get(tagName)) {
                defineCustomElement$l();
            }
            break;
        case "form-control-select":
            if (!customElements.get(tagName)) {
                defineCustomElement$k();
            }
            break;
        case "form-control-text":
            if (!customElements.get(tagName)) {
                defineCustomElement$j();
            }
            break;
        case "form-control-tooltip":
            if (!customElements.get(tagName)) {
                defineCustomElement$i();
            }
            break;
        case "hidden-input":
            if (!customElements.get(tagName)) {
                defineCustomElement$h();
            }
            break;
        case "iframe-input":
            if (!customElements.get(tagName)) {
                defineCustomElement$g();
            }
            break;
        case "internal-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$f();
            }
            break;
        case "justifi-apple-pay":
            if (!customElements.get(tagName)) {
                defineCustomElement$e();
            }
            break;
        case "justifi-button":
            if (!customElements.get(tagName)) {
                defineCustomElement$d();
            }
            break;
        case "justifi-checkout-summary":
            if (!customElements.get(tagName)) {
                defineCustomElement$c();
            }
            break;
        case "justifi-google-pay":
            if (!customElements.get(tagName)) {
                defineCustomElement$b();
            }
            break;
        case "justifi-header":
            if (!customElements.get(tagName)) {
                defineCustomElement$a();
            }
            break;
        case "justifi-modular-checkout":
            if (!customElements.get(tagName)) {
                defineCustomElement$9();
            }
            break;
        case "justifi-plaid-payment-method":
            if (!customElements.get(tagName)) {
                defineCustomElement$8();
            }
            break;
        case "justifi-radio-list-item":
            if (!customElements.get(tagName)) {
                defineCustomElement$7();
            }
            break;
        case "justifi-saved-payment-methods":
            if (!customElements.get(tagName)) {
                defineCustomElement$6();
            }
            break;
        case "justifi-sezzle-payment-method":
            if (!customElements.get(tagName)) {
                defineCustomElement$5();
            }
            break;
        case "justifi-tokenize-payment-method":
            if (!customElements.get(tagName)) {
                defineCustomElement$4();
            }
            break;
        case "radio-list-item":
            if (!customElements.get(tagName)) {
                defineCustomElement$3();
            }
            break;
        case "save-new-payment-method":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
    } });
}
defineCustomElement$1();

const JustifiCheckout = JustifiCheckout$1;
const defineCustomElement = defineCustomElement$1;

export { JustifiCheckout, defineCustomElement };
