import { h, Host, } from "@stencil/core";
import { checkoutStore, onAnyChange, getAvailablePaymentMethodTypes, getCheckoutState } from "../../store/checkout.store";
import JustifiAnalytics from "../../api/Analytics";
import { checkPkgVersion } from "../../utils/check-pkg-version";
import { ComponentErrorCodes, ComponentErrorMessages, ComponentErrorSeverity, ICheckoutStatus, } from "../../api";
import { makeCheckoutComplete, makeGetCheckout, } from "../../actions/checkout/checkout-actions";
import { CheckoutService } from "../../api/services/checkout.service";
import { PlaidService } from "../../api/services/plaid.service";
import { insuranceValues, insuranceValuesOn, hasInsuranceValueChanged } from "../insurance/insurance-state";
import { PAYMENT_MODE, PAYMENT_METHODS, PaymentMethod } from "./ModularCheckout";
export class JustifiModularCheckout {
    constructor() {
        this.plaidService = new PlaidService();
        this.handleApplePayStarted = () => {
            checkoutStore.isWalletProcessing = true;
        };
        this.handleGooglePayStarted = () => {
            checkoutStore.isWalletProcessing = true;
        };
        this.handleGooglePayCompleted = (event) => {
            const { success, paymentMethodId, error } = event.detail || {};
            if (success && paymentMethodId) {
                checkoutStore.isWalletProcessing = false;
                checkoutStore.paymentToken = paymentMethodId;
                checkoutStore.selectedPaymentMethod = { type: PAYMENT_METHODS.GOOGLE_PAY };
                this.submitCheckout();
            }
            else {
                checkoutStore.isWalletProcessing = false;
                this.errorEvent.emit({
                    message: (error && error.message) || "Google Pay payment failed",
                    errorCode: ComponentErrorCodes.TOKENIZE_ERROR,
                    severity: ComponentErrorSeverity.ERROR,
                });
            }
        };
        this.handleGooglePayCancelled = () => {
            checkoutStore.isWalletProcessing = false;
            checkoutStore.paymentToken = undefined;
            checkoutStore.selectedPaymentMethod = undefined;
        };
        this.handleApplePayCompleted = (event) => {
            const { success, token, paymentMethodId, error } = event.detail;
            if (success && token) {
                checkoutStore.isWalletProcessing = false;
                checkoutStore.paymentToken = paymentMethodId;
                checkoutStore.selectedPaymentMethod = { type: PAYMENT_METHODS.APPLE_PAY };
                this.submitCheckout();
            }
            else {
                checkoutStore.isWalletProcessing = false;
                console.error("Apple Pay completed but failed:", error);
                this.errorEvent.emit({
                    message: (error === null || error === void 0 ? void 0 : error.message) || "Apple Pay payment failed",
                    errorCode: ComponentErrorCodes.TOKENIZE_ERROR,
                    severity: ComponentErrorSeverity.ERROR,
                });
            }
        };
        this.handleApplePayError = (event) => {
            checkoutStore.isWalletProcessing = false;
            const { error, code } = event.detail;
            console.error("Apple Pay error:", error);
            this.errorEvent.emit({
                message: error || "Apple Pay error occurred",
                // prefix with APPLE_PAY_
                errorCode: `APPLE_PAY_${code}`,
                severity: ComponentErrorSeverity.ERROR,
            });
        };
        this.handleApplePayCancelled = () => {
            checkoutStore.isWalletProcessing = false;
            checkoutStore.paymentToken = undefined;
            checkoutStore.selectedPaymentMethod = undefined;
        };
    }
    connectedCallback() {
        this.observer = new MutationObserver(() => {
            this.queryFormRefs();
            this.setupApplePayListeners(); // set up again listeners when DOM changes
            this.setupGooglePayListeners();
        });
        this.observer.observe(this.hostEl, {
            childList: true,
            subtree: true,
        });
        checkoutStore.checkoutId = this.checkoutId;
        const config = {
            authToken: this.authToken,
            checkoutId: this.checkoutId,
            service: new CheckoutService(),
        };
        this.getCheckout = makeGetCheckout(config);
        this.completeCheckout = makeCheckoutComplete(config);
        // Emit checkout-changed whenever any store key changes
        onAnyChange(() => {
            this.emitCheckoutChanged();
        });
    }
    componentWillLoad() {
        this.analytics = new JustifiAnalytics(this);
        checkPkgVersion();
        checkoutStore.authToken = this.authToken;
        this.fetchCheckout();
        // Refresh the checkout data when insurance values actually change (not on initial load)
        insuranceValuesOn("set", (key) => {
            const value = insuranceValues[key];
            if (value !== undefined && hasInsuranceValueChanged(key, value)) {
                this.fetchCheckout();
            }
        });
    }
    componentDidLoad() {
        this.queryFormRefs();
        this.setupApplePayListeners();
        this.setupGooglePayListeners();
    }
    disconnectedCallback() {
        var _a;
        (_a = this.observer) === null || _a === void 0 ? void 0 : _a.disconnect();
        this.removeApplePayListeners();
        this.removeGooglePayListeners();
    }
    fetchCheckout() {
        if (!this.authToken || !this.checkoutId) {
            this.errorEvent.emit({
                message: ComponentErrorMessages.NOT_AUTHENTICATED,
                errorCode: ComponentErrorCodes.NOT_AUTHENTICATED,
                severity: ComponentErrorSeverity.ERROR,
            });
            return;
        }
        if (this.getCheckout) {
            this.getCheckout({
                onSuccess: ({ checkout }) => {
                    this.updateStore(checkout);
                    if (checkout.status === ICheckoutStatus.completed) {
                        this.errorEvent.emit({
                            message: ComponentErrorMessages.CHECKOUT_ALREADY_COMPLETED,
                            errorCode: ComponentErrorCodes.CHECKOUT_ALREADY_COMPLETED,
                            severity: ComponentErrorSeverity.ERROR,
                        });
                        return;
                    }
                    else if (checkout.status === ICheckoutStatus.expired) {
                        this.errorEvent.emit({
                            message: ComponentErrorMessages.CHECKOUT_EXPIRED,
                            errorCode: ComponentErrorCodes.CHECKOUT_EXPIRED,
                            severity: ComponentErrorSeverity.ERROR,
                        });
                        return;
                    }
                },
                onError: (error) => {
                    this.errorEvent.emit({
                        message: error.message,
                        errorCode: error.code,
                        severity: error.severity,
                    });
                },
            });
        }
    }
    updateStore(checkout) {
        var _a, _b, _c, _d, _e, _f, _g, _h;
        checkoutStore.accountId = checkout.account_id;
        checkoutStore.checkoutLoaded = true;
        const rawMode = checkout.mode != null ? String(checkout.mode).toLowerCase() : '';
        checkoutStore.checkoutMode =
            rawMode === 'test' ? 'test' : rawMode === 'live' ? 'live' : null;
        const mappedPaymentMethods = checkout.payment_methods.map((paymentMethod) => new PaymentMethod(paymentMethod));
        const achEnabled = Boolean((_a = checkout.payment_settings) === null || _a === void 0 ? void 0 : _a.ach_payments);
        checkoutStore.paymentMethods = mappedPaymentMethods.filter((pm) => pm.type !== PAYMENT_METHODS.SAVED_BANK_ACCOUNT || achEnabled);
        checkoutStore.paymentMethodGroupId = checkout.payment_method_group_id;
        checkoutStore.paymentDescription = checkout.payment_description;
        checkoutStore.totalAmount = checkout.total_amount;
        checkoutStore.paymentAmount = checkout.payment_amount;
        checkoutStore.bnplEnabled = checkout.payment_settings.bnpl_payments;
        checkoutStore.insuranceEnabled = checkout.payment_settings.insurance_payments;
        checkoutStore.bankAccountVerification = (_b = checkout.payment_settings) === null || _b === void 0 ? void 0 : _b.bank_account_verification;
        checkoutStore.applePayEnabled = (_c = checkout.payment_settings) === null || _c === void 0 ? void 0 : _c.apple_payments;
        checkoutStore.googlePayEnabled = (_d = checkout.payment_settings) === null || _d === void 0 ? void 0 : _d.google_payments;
        checkoutStore.achPaymentsEnabled = achEnabled;
        checkoutStore.bnplProviderClientId = (_e = checkout === null || checkout === void 0 ? void 0 : checkout.bnpl) === null || _e === void 0 ? void 0 : _e.provider_client_id;
        checkoutStore.bnplProviderMode = (_f = checkout === null || checkout === void 0 ? void 0 : checkout.bnpl) === null || _f === void 0 ? void 0 : _f.provider_mode;
        checkoutStore.bnplProviderApiVersion = (_g = checkout === null || checkout === void 0 ? void 0 : checkout.bnpl) === null || _g === void 0 ? void 0 : _g.provider_api_version;
        checkoutStore.bnplProviderCheckoutUrl =
            (_h = checkout === null || checkout === void 0 ? void 0 : checkout.bnpl) === null || _h === void 0 ? void 0 : _h.provider_checkout_url;
    }
    emitCheckoutChanged() {
        const detail = {
            availablePaymentMethodTypes: getAvailablePaymentMethodTypes(),
            selectedPaymentMethod: checkoutStore.selectedPaymentMethod,
            savedPaymentMethods: checkoutStore.paymentMethods,
        };
        this.checkoutChangedEvent.emit(detail);
    }
    queryFormRefs() {
        this.billingFormRef = this.hostEl.querySelector("justifi-billing-form, justifi-bank-account-billing-form-simple, justifi-card-billing-form-simple, justifi-billing-form-full, justifi-tokenize-payment-method");
        this.applePayRef = this.hostEl.querySelector("justifi-apple-pay");
        this.googlePayRef = this.hostEl.querySelector("justifi-google-pay");
        this.paymentMethodFormRef =
            this.hostEl.querySelector('justifi-card-form, justifi-bank-account-form, justifi-tokenize-payment-method');
        if (!checkoutStore.selectedPaymentMethod && this.paymentMethodFormRef) {
            const tag = this.paymentMethodFormRef.tagName.toLowerCase();
            if (tag === 'justifi-card-form') {
                checkoutStore.selectedPaymentMethod = { type: PAYMENT_METHODS.NEW_CARD };
            }
            else if (tag === 'justifi-bank-account-form' &&
                (!checkoutStore.checkoutLoaded || checkoutStore.achPaymentsEnabled)) {
                checkoutStore.selectedPaymentMethod = { type: PAYMENT_METHODS.NEW_BANK_ACCOUNT };
            }
        }
        this.insuranceFormRef = this.hostEl.querySelector('justifi-season-interruption-insurance');
    }
    setupApplePayListeners() {
        if (this.applePayRef) {
            this.applePayRef.addEventListener("applePayStarted", this.handleApplePayStarted);
            this.applePayRef.addEventListener("applePayCompleted", this.handleApplePayCompleted);
            this.applePayRef.addEventListener("applePayError", this.handleApplePayError);
            this.applePayRef.addEventListener("applePayCancelled", this.handleApplePayCancelled);
        }
    }
    removeApplePayListeners() {
        if (this.applePayRef) {
            this.applePayRef.removeEventListener("applePayStarted", this.handleApplePayStarted);
            this.applePayRef.removeEventListener("applePayCompleted", this.handleApplePayCompleted);
            this.applePayRef.removeEventListener("applePayError", this.handleApplePayError);
            this.applePayRef.removeEventListener("applePayCancelled", this.handleApplePayCancelled);
        }
    }
    setupGooglePayListeners() {
        if (this.googlePayRef) {
            this.googlePayRef.addEventListener("googlePayStarted", this.handleGooglePayStarted);
            this.googlePayRef.addEventListener("googlePayCompleted", this.handleGooglePayCompleted);
            this.googlePayRef.addEventListener("googlePayCancelled", this.handleGooglePayCancelled);
        }
    }
    removeGooglePayListeners() {
        if (this.googlePayRef) {
            this.googlePayRef.removeEventListener("googlePayStarted", this.handleGooglePayStarted);
            this.googlePayRef.removeEventListener("googlePayCompleted", this.handleGooglePayCompleted);
            this.googlePayRef.removeEventListener("googlePayCancelled", this.handleGooglePayCancelled);
        }
    }
    async tokenizePaymentMethod(tokenizeArgs) {
        var _a, _b, _c;
        const billingInfoValues = (_b = (await ((_a = this.billingFormRef) === null || _a === void 0 ? void 0 : _a.getValues()))) !== null && _b !== void 0 ? _b : {};
        const combinedBillingInfo = Object.assign(Object.assign({}, tokenizeArgs), billingInfoValues);
        const paymentMethodMetadata = Object.assign({ accountId: checkoutStore.accountId, payment_method_group_id: undefined }, combinedBillingInfo);
        if (checkoutStore.savePaymentMethod) {
            paymentMethodMetadata.payment_method_group_id =
                checkoutStore.paymentMethodGroupId;
        }
        const tokenizeResult = await ((_c = this.paymentMethodFormRef) === null || _c === void 0 ? void 0 : _c.tokenize({
            clientId: this.authToken,
            paymentMethodMetadata,
            account: checkoutStore.accountId,
        }));
        if (tokenizeResult.error) {
            return tokenizeResult;
        }
        checkoutStore.paymentToken = tokenizeResult.id;
        return tokenizeResult.id;
    }
    async fillBillingForm(fields) {
        checkoutStore.billingFormFields = fields;
    }
    // set the selected payment method to the checkout store from outside the component
    async setSelectedPaymentMethod(paymentMethod) {
        checkoutStore.selectedPaymentMethod = paymentMethod;
        checkoutStore.paymentToken = paymentMethod.id || undefined;
    }
    // if validation fails, the error will be emitted by the component
    async validate() {
        var _a, _b;
        const promises = [];
        if (checkoutStore.insuranceEnabled && this.insuranceFormRef) {
            promises.push(this.insuranceFormRef.validate());
        }
        const isNewCard = ((_a = checkoutStore.selectedPaymentMethod) === null || _a === void 0 ? void 0 : _a.type) === PAYMENT_METHODS.NEW_CARD;
        const isNewBankAccount = ((_b = checkoutStore.selectedPaymentMethod) === null || _b === void 0 ? void 0 : _b.type) === PAYMENT_METHODS.NEW_BANK_ACCOUNT;
        // For new card/bank account, validate payment method + billing.
        if (isNewCard || isNewBankAccount) {
            if (this.paymentMethodFormRef)
                promises.push(this.paymentMethodFormRef.validate());
            if (this.billingFormRef)
                promises.push(this.billingFormRef.validate());
        }
        if (promises.length === 0)
            return true;
        try {
            const results = await Promise.all(promises);
            // Normalize different validator return shapes:
            // - boolean -> use it directly
            // - object  -> look for isValid; treat missing isValid as falsey only if explicitly false
            const resultsAreValid = results.every(r => typeof r === 'boolean' ? r : (r === null || r === void 0 ? void 0 : r.isValid) !== false);
            if (!resultsAreValid) {
                this.errorEvent.emit({
                    message: 'Validation error',
                    errorCode: ComponentErrorCodes.VALIDATION_ERROR,
                    severity: ComponentErrorSeverity.ERROR,
                });
                return false;
            }
            return true;
        }
        catch (_c) {
            // If any validator throws/rejects, consider the whole validation failed.
            return false;
        }
    }
    async submitCheckout(submitCheckoutArgs) {
        var _a, _b, _c, _d, _e;
        if (checkoutStore.isSubmitting)
            return;
        checkoutStore.isSubmitting = true;
        const isValid = await this.validate();
        if (!checkoutStore.selectedPaymentMethod) {
            checkoutStore.isSubmitting = false;
            this.errorEvent.emit({
                message: 'No payment method selected.',
                errorCode: ComponentErrorCodes.VALIDATION_ERROR,
                severity: ComponentErrorSeverity.ERROR,
            });
            return;
        }
        const isNewCard = ((_a = checkoutStore.selectedPaymentMethod) === null || _a === void 0 ? void 0 : _a.type) === PAYMENT_METHODS.NEW_CARD;
        const isNewBankAccount = ((_b = checkoutStore.selectedPaymentMethod) === null || _b === void 0 ? void 0 : _b.type) === PAYMENT_METHODS.NEW_BANK_ACCOUNT;
        const isPlaid = ((_c = checkoutStore.selectedPaymentMethod) === null || _c === void 0 ? void 0 : _c.type) === PAYMENT_METHODS.PLAID;
        const shouldTokenize = isNewCard || isNewBankAccount;
        if (shouldTokenize) {
            const tokenizeResult = await this.tokenizePaymentMethod(submitCheckoutArgs);
            if (tokenizeResult === null || tokenizeResult === void 0 ? void 0 : tokenizeResult.error) {
                checkoutStore.isSubmitting = false;
                this.errorEvent.emit({
                    message: tokenizeResult.error.message,
                    errorCode: ComponentErrorCodes.TOKENIZE_ERROR,
                    severity: ComponentErrorSeverity.ERROR,
                });
                return;
            }
        }
        // For Plaid, perform exchange at submit time using stored public token and link token id
        if (isPlaid && !checkoutStore.paymentToken) {
            const publicToken = checkoutStore.plaidPublicToken;
            const linkTokenId = checkoutStore.plaidLinkTokenId;
            if (!publicToken) {
                checkoutStore.isSubmitting = false;
                this.errorEvent.emit({
                    message: 'Missing Plaid public token. Please connect your bank.',
                    errorCode: ComponentErrorCodes.TOKENIZE_ERROR,
                    severity: ComponentErrorSeverity.ERROR,
                });
                return;
            }
            try {
                const response = await this.plaidService.tokenizeBankAccount(checkoutStore.authToken, checkoutStore.accountId, publicToken, linkTokenId || undefined, checkoutStore.savePaymentMethod ? checkoutStore.paymentMethodGroupId : undefined);
                if (response === null || response === void 0 ? void 0 : response.error) {
                    checkoutStore.isSubmitting = false;
                    this.errorEvent.emit({
                        message: typeof response.error === 'string' ? response.error : response.error.message || 'Failed to tokenize bank account',
                        errorCode: ComponentErrorCodes.TOKENIZE_ERROR,
                        severity: ComponentErrorSeverity.ERROR,
                    });
                    return;
                }
                const paymentMethod = response === null || response === void 0 ? void 0 : response.data;
                const token = ((_d = paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.bank_account) === null || _d === void 0 ? void 0 : _d.token) || (paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.token) || (paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.id);
                checkoutStore.paymentToken = token;
            }
            catch (err) {
                checkoutStore.isSubmitting = false;
                this.errorEvent.emit({
                    message: (err === null || err === void 0 ? void 0 : err.message) || 'Plaid exchange error',
                    errorCode: ComponentErrorCodes.TOKENIZE_ERROR,
                    severity: ComponentErrorSeverity.ERROR,
                });
                return;
            }
        }
        if (!isValid) {
            checkoutStore.isSubmitting = false;
            this.errorEvent.emit({
                message: "Please fill in all required fields.",
                errorCode: ComponentErrorCodes.VALIDATION_ERROR,
                severity: ComponentErrorSeverity.ERROR,
            });
            return;
        }
        if (!checkoutStore.paymentToken) {
            checkoutStore.isSubmitting = false;
            this.errorEvent.emit({
                message: 'Payment token not found.',
                errorCode: ComponentErrorCodes.TOKENIZE_ERROR,
                severity: ComponentErrorSeverity.ERROR,
            });
            return;
        }
        const mapTypeToPaymentMode = (type) => {
            switch (type) {
                case PAYMENT_METHODS.NEW_CARD:
                case PAYMENT_METHODS.SAVED_CARD:
                case PAYMENT_METHODS.NEW_BANK_ACCOUNT:
                case PAYMENT_METHODS.SAVED_BANK_ACCOUNT:
                case PAYMENT_METHODS.PLAID:
                    return PAYMENT_MODE.ECOM;
                case PAYMENT_METHODS.SEZZLE:
                    return PAYMENT_MODE.BNPL;
                case PAYMENT_METHODS.APPLE_PAY:
                    return PAYMENT_MODE.APPLE_PAY;
                case PAYMENT_METHODS.GOOGLE_PAY:
                    return PAYMENT_MODE.GOOGLE_PAY;
                default:
                    return undefined;
            }
        };
        const payment = {
            payment_mode: mapTypeToPaymentMode((_e = checkoutStore.selectedPaymentMethod) === null || _e === void 0 ? void 0 : _e.type),
            payment_token: checkoutStore.paymentToken,
        };
        if (this.preCompleteHook) {
            const state = getCheckoutState();
            try {
                await new Promise((resolve, reject) => {
                    this.preCompleteHook(state, () => resolve(), () => reject());
                });
            }
            catch (error) {
                checkoutStore.isSubmitting = false;
                console.log('Checkout cancelled by preCompleteHook', error);
                return;
            }
        }
        this.completeCheckout({
            payment,
            onSuccess: ({ checkout }) => {
                checkoutStore.isSubmitting = false;
                this.submitEvent.emit({
                    checkout,
                    message: "Checkout completed successfully",
                });
            },
            onError: (error) => {
                checkoutStore.isSubmitting = false;
                this.errorEvent.emit({
                    message: error.message,
                    errorCode: ComponentErrorCodes.COMPLETE_CHECKOUT_ERROR,
                    severity: ComponentErrorSeverity.ERROR,
                });
            },
        });
    }
    render() {
        return h(Host, { key: '545e1cb07252ba0dc78fa980bd17ee5572559f6c' });
    }
    static get is() { return "justifi-modular-checkout"; }
    static get properties() {
        return {
            "authToken": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "auth-token"
            },
            "checkoutId": {
                "type": "string",
                "mutable": false,
                "complexType": {
                    "original": "string",
                    "resolved": "string",
                    "references": {}
                },
                "required": true,
                "optional": false,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false,
                "reflect": false,
                "attribute": "checkout-id"
            },
            "preCompleteHook": {
                "type": "unknown",
                "mutable": false,
                "complexType": {
                    "original": "Hook<CheckoutState>",
                    "resolved": "(data: CheckoutState, resolve: (data: CheckoutState) => void, reject: () => void) => void",
                    "references": {
                        "Hook": {
                            "location": "import",
                            "path": "./ModularCheckout",
                            "id": "src/components/modular-checkout/ModularCheckout.ts::Hook"
                        },
                        "CheckoutState": {
                            "location": "import",
                            "path": "../../store/checkout.store",
                            "id": "src/store/checkout.store.ts::CheckoutState"
                        }
                    }
                },
                "required": false,
                "optional": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "getter": false,
                "setter": false
            }
        };
    }
    static get events() {
        return [{
                "method": "errorEvent",
                "name": "error-event",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "submitEvent",
                "name": "submit-event",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "any",
                    "resolved": "any",
                    "references": {}
                }
            }, {
                "method": "checkoutChangedEvent",
                "name": "checkout-changed",
                "bubbles": true,
                "cancelable": true,
                "composed": true,
                "docs": {
                    "tags": [],
                    "text": ""
                },
                "complexType": {
                    "original": "CheckoutChangedEventDetail",
                    "resolved": "CheckoutChangedEventDetail",
                    "references": {
                        "CheckoutChangedEventDetail": {
                            "location": "import",
                            "path": "./ModularCheckout",
                            "id": "src/components/modular-checkout/ModularCheckout.ts::CheckoutChangedEventDetail"
                        }
                    }
                }
            }];
    }
    static get methods() {
        return {
            "fillBillingForm": {
                "complexType": {
                    "signature": "(fields: BillingFormFields) => Promise<void>",
                    "parameters": [{
                            "name": "fields",
                            "type": "BillingFormFields",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "BillingFormFields": {
                            "location": "import",
                            "path": "../../components",
                            "id": "src/components.d.ts::BillingFormFields"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "setSelectedPaymentMethod": {
                "complexType": {
                    "signature": "(paymentMethod: SelectedPaymentMethod) => Promise<void>",
                    "parameters": [{
                            "name": "paymentMethod",
                            "type": "{ id?: string; type: PAYMENT_METHODS; }",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "SelectedPaymentMethod": {
                            "location": "import",
                            "path": "./ModularCheckout",
                            "id": "src/components/modular-checkout/ModularCheckout.ts::SelectedPaymentMethod"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "validate": {
                "complexType": {
                    "signature": "() => Promise<boolean>",
                    "parameters": [],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        }
                    },
                    "return": "Promise<boolean>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            },
            "submitCheckout": {
                "complexType": {
                    "signature": "(submitCheckoutArgs?: BillingFormFields) => Promise<void>",
                    "parameters": [{
                            "name": "submitCheckoutArgs",
                            "type": "BillingFormFields",
                            "docs": ""
                        }],
                    "references": {
                        "Promise": {
                            "location": "global",
                            "id": "global::Promise"
                        },
                        "BillingFormFields": {
                            "location": "import",
                            "path": "../../components",
                            "id": "src/components.d.ts::BillingFormFields"
                        }
                    },
                    "return": "Promise<void>"
                },
                "docs": {
                    "text": "",
                    "tags": []
                }
            }
        };
    }
    static get elementRef() { return "hostEl"; }
}
