var Wick = Wick || {};

const paymentLoader = '.payment-loader';
const paymentLoaderHideClass = 'payment-loader--hidden';
const paymentLoaderModal = '.payment-loader__modal';
const paymentTypeSelectors = {
    apple: '.apple__button',
    google: '.google__button',
    clearpay: '#checkout-payment-details-clearpay',
    paypal: '#checkout-payment-details-paypal',
};

Wick.showPaymentLoader = function (paymentType) {
    $(paymentLoader).find(`${paymentLoaderModal} > div`).hide();
    $(`.${paymentType}-checkout-logo`).show();
    $(`${paymentLoader} .spinner`).show();
    $(paymentLoader).removeClass(paymentLoaderHideClass);

    setTimeout(() => {
        $(paymentLoader).addClass(paymentLoaderHideClass);
    }, 1000);
};

Object.entries(paymentTypeSelectors).forEach(([type, triggerSelector]) => {
    $(document).on('click', triggerSelector, () => Wick.showPaymentLoader(type));
});
