'use strict';

var index = require('./index-p7cvUYAE.js');
var Analytics = require('./Analytics-C6KBHEIP.js');
var checkPkgVersion = require('./check-pkg-version-B9EoYyZR.js');
var checkout_store = require('./checkout.store-CZHrIuaP.js');
var parts = require('./parts-BXshb_S-.js');
var styledHost = require('./styled-host-Ch0-dxF-.js');
require('./event-types-YOY5TKUN.js');
var index$1 = require('./index-CajjbB9t.js');
require('./package-YyJzVqrh.js');
require('./Api-D9vOcUw4.js');
require('./config-state-BIgGhhe9.js');
require('./index-W-zoNiyM.js');
require('./utils-CYONRFR6.js');
require('./dinero-BwNN_k7x.js');
require('./Plaid-CPESyiiV.js');
require('./Pagination-Dediz133.js');
require('./Business-oBifyXkW.js');

const JustifiCheckout = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.errorEvent = index.createEvent(this, "error-event", 7);
        this.loadedEvent = index.createEvent(this, "loaded", 7);
        this.submitEvent = index.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.checkPkgVersion();
        this.analytics = new Analytics.JustifiAnalytics(this);
    }
    disconnectedCallback() {
        var _a;
        (_a = this.analytics) === null || _a === void 0 ? void 0 : _a.cleanup();
    }
    checkoutComplete(_event) {
        checkout_store.checkoutStore.isSubmitting = false;
    }
    checkoutError(_event) {
        checkout_store.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 !== index$1.PAYMENT_METHODS.SEZZLE);
            return;
        }
        this.availablePaymentMethods = event.detail.availablePaymentMethodTypes;
    }
    async fillBillingForm(fields) {
        checkout_store.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() {
        checkout_store.checkoutStore.checkoutId = this.checkoutId;
        checkout_store.checkoutStore.authToken = this.authToken;
        checkout_store.checkoutStore.disableCreditCard = this.disableCreditCard;
        checkout_store.checkoutStore.disableBankAccount = this.disableBankAccount;
        checkout_store.checkoutStore.disablePaymentMethodGroup = this.disablePaymentMethodGroup;
    }
    async submit(_event) {
        var _a;
        (_a = this.modularCheckoutRef) === null || _a === void 0 ? void 0 : _a.submitCheckout(checkout_store.checkoutStore.billingFormFields);
    }
    get showPaymentTypeHeader() {
        return !this.disableCreditCard && !this.disableBankAccount;
    }
    render() {
        var _a, _b;
        return (index.h(styledHost.StyledHost, { key: 'bc8428227b2fc0e0753c4ef4e2370cd34bd34e82' }, index.h("justifi-modular-checkout", { key: '9fda18728d6fb5b20716070cefc2fcf8ef097459', ref: (el) => {
                this.modularCheckoutRef = el;
            }, authToken: this.authToken, checkoutId: this.checkoutId, preCompleteHook: this.preCompleteHook }, index.h("div", { key: 'e39f9871696d44cea2080198c7b91d03b706f2fd', class: "row gy-3 jfi-checkout-core" }, index.h("div", { key: 'df6045e9394b10f9b3e4b86e1a2242db30cc9b7b', class: "col-12", part: parts.checkoutSummary }, index.h("justifi-header", { key: '8f4332bd43371106faf4e264fd5b27c97cb589aa', text: "Summary", level: "h2", class: "fs-5 fw-bold pb-3" }), index.h("section", { key: 'a7170276f18b9fa4b085c4d5de35979d55935929' }, index.h("justifi-checkout-summary", { key: '109aceb53ad2500e927230b3f82bbb07ab3f604c' }))), index.h("div", { key: '902e040bbd591408c9d292a592ca4d31fc838d85', class: "col-12 mt-4" }, index.h("slot", { key: '2677cb4952d88a8ce8f0198b96ed2638d4f4e6eb', name: "insurance" })), index.h("div", { key: '32c033bba12a7b7bf26159bd1878d6fa4ed913d9', class: "col-12 mt-4" }, index.h("justifi-header", { key: '74543b63c1b94a5200ad36236818fce7345d5d76', text: "Payment", level: "h2", class: "fs-5 fw-bold pb-3" }), this.showPaymentTypeHeader && (index.h("justifi-header", { key: '8e7c56c75bb779211b72c0b8561df8283b731ca1', text: "Select payment type", level: "h3", class: "fs-6 fw-bold lh-lg" })), index.h("div", { key: 'c2b0a875169b46dcd7d73428e3f1a4825b380ce5', class: "d-flex flex-column" }, index.h("section", { key: 'c5f007674c058e88d271c17f0b6b9c959bd0e044' }, index.h("div", { key: '2c4ecdd0f8708f9f80bae50362ba7fab295f788f' }, this.availablePaymentMethods.includes(index$1.PAYMENT_METHODS.APPLE_PAY) && (index.h("div", { key: '5ac363a3b7c38cb3f10e9c2c7916825f0f5dc2d8', class: "mb-3" }, index.h("justifi-apple-pay", { key: '498c03630e4057b54ebd12a3cd87b6b6bdb00c4b' }))), this.availablePaymentMethods.includes(index$1.PAYMENT_METHODS.GOOGLE_PAY) && (index.h("div", { key: '8c8114d142927739a3217d3a0a44c34c89e58f83', class: "mb-3" }, index.h("justifi-google-pay", Object.assign({ key: 'a2fbc5b99a83fbc52698422d2f57a3380f97733f', ref: (el) => (this.googlePayRef = el) }, (this.googlePayEnv != null ? { environment: this.googlePayEnv } : {}))))), index.h("justifi-saved-payment-methods", { key: '2e5b27eea7ef433e950feadae0b0a07f8b613533' }), this.availablePaymentMethods.includes(index$1.PAYMENT_METHODS.SEZZLE) && (index.h("justifi-radio-list-item", { key: 'fb1501c51eaf836579547bc50c295ebb67cb09c1', name: "paymentMethodType", value: index$1.PAYMENT_METHODS.SEZZLE, checked: ((_a = checkout_store.checkoutStore === null || checkout_store.checkoutStore === void 0 ? void 0 : checkout_store.checkoutStore.selectedPaymentMethod) === null || _a === void 0 ? void 0 : _a.type) === index$1.PAYMENT_METHODS.SEZZLE, label: index.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(index$1.PAYMENT_METHODS.PLAID) && !this.disableBnpl && (index.h("justifi-radio-list-item", { key: '49e0687b4955fb92935783250540fe38350bbdcc', name: "paymentMethodType", value: index$1.PAYMENT_METHODS.PLAID, checked: ((_b = checkout_store.checkoutStore === null || checkout_store.checkoutStore === void 0 ? void 0 : checkout_store.checkoutStore.selectedPaymentMethod) === null || _b === void 0 ? void 0 : _b.type) === index$1.PAYMENT_METHODS.PLAID, label: index.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(); } })), index.h("justifi-tokenize-payment-method", { key: 'ba793274de073c8a60c063e9caedcf32780b4bbf', ref: (el) => (this.tokenizePaymentMethodRef = el), authToken: this.authToken, accountId: checkout_store.checkoutStore.accountId, disableCreditCard: this.disableCreditCard, disableBankAccount: this.disableBankAccount, hideCardBillingForm: this.hideCardBillingForm, hideBankAccountBillingForm: this.hideBankAccountBillingForm, hideSubmitButton: true, paymentMethodGroupId: checkout_store.checkoutStore.paymentMethodGroupId }))))), index.h("div", { key: 'ed7be422c4e369382fd42e0b0162357df7de2031', class: "mt-4" }, index.h("justifi-button", { key: '849d648feec5ce805d6eb87acacf94d62e7a8f1b', text: "Pay", type: "submit", variant: "primary", clickHandler: (e) => this.submit(e), disabled: checkout_store.checkoutStore.isSubmitting || checkout_store.checkoutStore.isWalletProcessing, isLoading: checkout_store.checkoutStore.isSubmitting || checkout_store.checkoutStore.isWalletProcessing, customStyle: { width: '100%', textAlign: "center" } }))))));
    }
    static get watchers() { return {
        "authToken": ["propChanged"],
        "checkoutId": ["propChanged"],
        "disableCreditCard": ["propChanged"],
        "disableBankAccount": ["propChanged"],
        "disablePaymentMethodGroup": ["propChanged"]
    }; }
};

exports.justifi_checkout = JustifiCheckout;
