import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { u as radioListItem } from './parts.js';
import { S as StyledHost } from './styled-host.js';
import './justifi-details2.js';
import './event-types.js';
import './justifi-radio-list-item2.js';
import { c as checkoutStore } from './checkout.store.js';
import { C as CardBrandLabels } from './payment-method-option-utils.js';
import { P as PAYMENT_METHODS } from './ModularCheckout.js';
import { d as defineCustomElement$2 } from './form-control-help-text3.js';
import { d as defineCustomElement$1 } from './form-control-radio2.js';

const JustifiSavedPaymentMethods = /*@__PURE__*/ proxyCustomElement(class JustifiSavedPaymentMethods extends HTMLElement {
    constructor(registerHost) {
        super();
        if (registerHost !== false) {
            this.__registerHost();
        }
        this.__attachShadow();
        this.onPaymentMethodOptionClick = (paymentMethod) => (e) => {
            e.preventDefault();
            checkoutStore.selectedPaymentMethod = { id: paymentMethod.id, type: paymentMethod.type };
            checkoutStore.paymentToken = paymentMethod.id;
        };
        this.isAllowedPaymentMethod = (paymentMethodType) => {
            const isCard = paymentMethodType === PAYMENT_METHODS.SAVED_CARD;
            const isBankAccount = paymentMethodType === PAYMENT_METHODS.SAVED_BANK_ACCOUNT;
            if (isCard && checkoutStore.disableCreditCard) {
                return false;
            }
            if (isBankAccount && checkoutStore.disableBankAccount) {
                return false;
            }
            return true;
        };
    }
    componentWillLoad() {
        if (checkoutStore.checkoutLoaded) {
            if (!checkoutStore.paymentMethods.length) {
                console.warn('No saved payment methods available.');
            }
            if (checkoutStore.disablePaymentMethodGroup) {
                console.warn('Payment method group is disabled.');
            }
        }
    }
    render() {
        if (checkoutStore.disablePaymentMethodGroup) {
            return null;
        }
        return (h(StyledHost, null, h("div", { class: "saved-payment-methods" }, checkoutStore.paymentMethods.length ? checkoutStore.paymentMethods
            .filter((paymentMethod) => this.isAllowedPaymentMethod(paymentMethod.type))
            .map((paymentMethod) => (h("div", { class: "radio-list-item p-3", part: radioListItem, onClick: this.onPaymentMethodOptionClick(paymentMethod) }, h("form-control-radio", { name: "paymentMethodType", value: paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.id, checked: checkoutStore.paymentToken === (paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.id), label: `${CardBrandLabels[paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.brand] || ''} *${paymentMethod === null || paymentMethod === void 0 ? void 0 : paymentMethod.acct_last_four}` })))) : null)));
    }
}, [257, "justifi-saved-payment-methods"]);
function defineCustomElement() {
    if (typeof customElements === "undefined") {
        return;
    }
    const components = ["justifi-saved-payment-methods", "form-control-help-text", "form-control-radio"];
    components.forEach(tagName => { switch (tagName) {
        case "justifi-saved-payment-methods":
            if (!customElements.get(tagName)) {
                customElements.define(tagName, JustifiSavedPaymentMethods);
            }
            break;
        case "form-control-help-text":
            if (!customElements.get(tagName)) {
                defineCustomElement$2();
            }
            break;
        case "form-control-radio":
            if (!customElements.get(tagName)) {
                defineCustomElement$1();
            }
            break;
    } });
}
defineCustomElement();

export { JustifiSavedPaymentMethods as J, defineCustomElement as d };
