import { c as createStore } from './index3.js';
import { P as PAYMENT_METHODS } from './ModularCheckout.js';

const initialState = {
    accountId: '',
    authToken: '',
    billingFormFields: {
        address_postal_code: '',
    },
    bnplEnabled: false,
    isSubmitting: false,
    isWalletProcessing: false,
    applePayEnabled: false,
    googlePayEnabled: false,
    achPaymentsEnabled: false,
    insuranceEnabled: false,
    bnplProviderApiVersion: '',
    bnplProviderCheckoutUrl: '',
    bnplProviderClientId: '',
    bnplProviderMode: '',
    checkoutId: '',
    checkoutLoaded: false,
    checkoutMode: null,
    bankAccountVerification: undefined,
    disableBankAccount: false,
    disableCreditCard: false,
    disablePaymentMethodGroup: false,
    paymentAmount: 0,
    paymentCurrency: 'USD',
    paymentDescription: '',
    paymentMethodGroupId: undefined,
    paymentMethods: [],
    paymentToken: undefined,
    savePaymentMethod: false,
    selectedPaymentMethod: undefined,
    totalAmount: 0,
    plaidPublicToken: undefined,
    plaidLinkTokenId: undefined,
};
const { state: checkoutStore, onChange } = createStore(initialState);
Object.keys(initialState).forEach((key) => {
    // @ts-ignore
    onChange(key, (newValue) => {
        checkoutStore[key] = newValue;
    });
});
// Helper: compute available payment methods based on store flags
function getAvailablePaymentMethodTypes() {
    var _a;
    const methods = [];
    const achAllowedForCheckout = !checkoutStore.checkoutLoaded || checkoutStore.achPaymentsEnabled;
    if (!checkoutStore.disablePaymentMethodGroup &&
        ((_a = checkoutStore.paymentMethods) === null || _a === void 0 ? void 0 : _a.length)) {
        const hasSavedCard = checkoutStore.paymentMethods.some((pm) => pm.type === PAYMENT_METHODS.SAVED_CARD);
        const hasSavedBank = checkoutStore.paymentMethods.some((pm) => pm.type === PAYMENT_METHODS.SAVED_BANK_ACCOUNT);
        if (hasSavedCard && !checkoutStore.disableCreditCard) {
            methods.push(PAYMENT_METHODS.SAVED_CARD);
        }
        if (hasSavedBank &&
            !checkoutStore.disableBankAccount &&
            achAllowedForCheckout) {
            methods.push(PAYMENT_METHODS.SAVED_BANK_ACCOUNT);
        }
    }
    if (!checkoutStore.disableCreditCard) {
        methods.push(PAYMENT_METHODS.NEW_CARD);
    }
    if (!checkoutStore.disableBankAccount && achAllowedForCheckout) {
        methods.push(PAYMENT_METHODS.NEW_BANK_ACCOUNT);
    }
    if (checkoutStore.bnplEnabled) {
        methods.push(PAYMENT_METHODS.SEZZLE);
    }
    if (checkoutStore.applePayEnabled) {
        methods.push(PAYMENT_METHODS.APPLE_PAY);
    }
    if (checkoutStore.googlePayEnabled) {
        methods.push(PAYMENT_METHODS.GOOGLE_PAY);
    }
    if (checkoutStore.bankAccountVerification === true &&
        !checkoutStore.disableBankAccount &&
        achAllowedForCheckout) {
        methods.push(PAYMENT_METHODS.PLAID);
    }
    return methods;
}
function getCheckoutState() {
    var _a;
    return {
        selectedPaymentMethod: checkoutStore.selectedPaymentMethod,
        paymentAmount: checkoutStore.paymentAmount,
        totalAmount: checkoutStore.totalAmount,
        paymentCurrency: checkoutStore.paymentCurrency,
        paymentDescription: checkoutStore.paymentDescription,
        savedPaymentMethods: checkoutStore.paymentMethods,
        savePaymentMethod: checkoutStore.savePaymentMethod,
        bnplEnabled: checkoutStore.bnplEnabled,
        applePayEnabled: checkoutStore.applePayEnabled,
        insuranceEnabled: checkoutStore.insuranceEnabled,
        disableBankAccount: checkoutStore.disableBankAccount,
        disableCreditCard: checkoutStore.disableCreditCard,
        disablePaymentMethodGroup: checkoutStore.disablePaymentMethodGroup,
        paymentToken: (_a = checkoutStore.paymentToken) !== null && _a !== void 0 ? _a : undefined,
    };
}
function onAnyChange(callback) {
    Object.keys(initialState).forEach((key) => {
        // @ts-ignore - onChange is generically typed by stencil/store but not exported here
        onChange(key, (newValue) => callback(key, newValue));
    });
}

export { onAnyChange as a, getCheckoutState as b, checkoutStore as c, getAvailablePaymentMethodTypes as g, onChange as o };
