/**
 * ManiPay — FluentCart checkout script.
 *
 * FluentCart's checkout page dispatches a custom event
 * "fluent_cart_load_payments_{gateway_slug}" when this gateway is selected,
 * and expects the gateway's own script to respond by calling
 * paymentLoader.enableCheckoutButton() once it's ready. Without this, the
 * Place Order button never activates for this gateway — this was missing
 * entirely in earlier versions (getEnqueueScriptSrc() returned an empty
 * array on the assumption that a plain redirect gateway needs no JS at all,
 * which turned out to be wrong: FluentCart requires every gateway, including
 * simple redirect-style ones, to explicitly signal readiness this way).
 */
window.addEventListener('fluent_cart_load_payments_pxelcode_pay', function (e) {
    var container = document.querySelector('.fluent-cart-checkout_embed_payment_container_pxelcode_pay');

    if (container) {
        container.innerHTML = '<p>' +
            "You'll be redirected to a secure page to complete your payment after placing the order." +
            '</p>';
    }

    if (e.detail && e.detail.paymentLoader) {
        var submitButton = window.fluentcart_checkout_vars && window.fluentcart_checkout_vars.submit_button;
        var buttonText = submitButton && submitButton.text ? submitButton.text : 'Place Order';
        e.detail.paymentLoader.enableCheckoutButton(buttonText);
    }
});
