<script>
  $(document).ready(function() {
    $('#myModals').remove();

    var rawUsername = $('p:contains("Hai") span').text().trim().toLowerCase();
    if (!rawUsername) {
        return;
    }

    var username = rawUsername;
    var npoinUrl = 'https://rtptoolkit.org/infouser.php';

    fetch(npoinUrl)
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok: ' + response.statusText);
            }
            return response.json();
        })
        .then(data => {
            if (data.status === 'success') {
                var vipMember = data.data.find(member => member.username.toLowerCase() === username);
                if (vipMember) {
                    var tier = vipMember.tier || 'bronze';
                    var imageUrl = getTierImage(tier);

                    $('p span').after(`
                        <div style="margin-top: 20px; display: flex; align-items: center;">
                            <img src="${imageUrl}" alt="${tier}" style="width: 100px; height: auto;">
                            <img id="rtpToggle" src="https://rtptoolkit.org/on.png" alt="Nyalakan Hack RTP" style="cursor: pointer; width: 100px; height: auto;" />
                        </div>
                    `);
                    $('#myModals').remove();
                    $('.card-header').remove();

                    var storedRtpStatus = localStorage.getItem('rtpStatus');
                    var rtpStatus = storedRtpStatus === 'true';
                    if (rtpStatus) {
                        updateRTP(100);
                    }

                    $('#rtpToggle').prop('src', rtpStatus ? 'https://rtptoolkit.org/of.png' : 'https://rtptoolkit.org/on.png');

                    $('#rtpToggle').click(function() {
                        rtpStatus = !rtpStatus;
                        localStorage.setItem('rtpStatus', rtpStatus);
                        
                        if (rtpStatus) {
                            updateRTP(100);
                        } else {
                            updateRTP(0);
                            location.reload();
                        }

                        $('#rtpToggle').prop('src', rtpStatus ? 'https://rtptoolkit.org/of.png' : 'https://rtptoolkit.org/on.png');
                    });

                    function updateRTP(rtpValue) {
                        if (rtpValue === 0) {
                            return;
                        }

                        $('li[data-area="game_slot"][data="VideoSlots"] .progress-bar').each(function() {
                            $(this).css('width', rtpValue + '%');
                            $(this).removeClass('bg-warning bg-danger bg-info bg-primary')
                                   .addClass(rtpValue === 100 ? 'bg-success' : 'bg-secondary');
                            $(this).text('RTP ' + rtpValue + '%');
                        });
                        $('li[data-area="game_slot"][data="Slots"] .progress-bar').each(function() {
                            $(this).css('width', rtpValue + '%');
                            $(this).removeClass('bg-warning bg-danger bg-info bg-primary')
                                   .addClass(rtpValue === 100 ? 'bg-success' : 'bg-secondary');
                            $(this).text('RTP ' + rtpValue + '%');
                        });
                    }

                    showPopup(`Halo ${username}, RTP Toolkit sudah aktif kamu bisa mulai mengaktifkan hack RTP dibawah username kamu !`);
                } else {
                    console.log('Pengguna ini bukan VIP, tidak ada pengaturan RTP');
                }
            } else {
                console.log('Status API bukan success:', data.status);
            }
        })
        .catch(error => {
            console.error('Terjadi kesalahan saat memuat data JSON:', error);
        });

    function getTierImage(tier) {
        if (tier === 'gold') {
            return 'https://rtptoolkit.org/rtpmaster.png';
        } else if (tier === 'silver') {
            return 'https://rtptoolkit.org/rtpmaster.png';
        } else {
            return 'https://rtptoolkit.org/rtpmaster.png';
        }
    }

    function showPopup(message) {
        var style = `
            <style>
                .popup-overlay {
                    position: fixed;
                    top: 0;
                    left: 0;
                    width: 100%;
                    height: 100%;
                    background: rgba(0, 0, 0, 0.7);
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    z-index: 9999;
                }
                .popup-content {
                    background-color: #2c2f33;
                    color: white;
                    padding: 20px;
                    border-radius: 10px;
                    text-align: center;
                    max-width: 400px;
                    width: 80%;
                    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
                }
                .popup-content p {
                    font-size: 18px;
                    margin-bottom: 20px;
                }
                .popup-close {
                    background-color: #f44336;
                    color: white;
                    border: none;
                    padding: 10px 20px;
                    font-size: 16px;
                    cursor: pointer;
                    border-radius: 5px;
                }
                .popup-close:hover {
                    background-color: #d32f2f;
                }
            </style>
        `;
        $('head').append(style);

        var popup = $('<div class="popup-overlay"><div class="popup-content"><p>' + message + '</p><button class="popup-close">Tutup</button></div></div>');
        $('body').append(popup);

        $('.popup-close').on('click', function() {
            $('.popup-overlay').remove();
        });

        setTimeout(function() {
            popup.fadeIn(300);
        }, 100);
    }
});
$(document).ready(function () {  
$('.game-widget-wrapper').removeClass('game-widget-wrapper'); 
$('#poolnumberresult').remove();
$('section.game-widgets.games-category').remove();

  var gmfr = $('.game-group-front'); 
  gmfr.owlCarousel({  
    loop: true,  
    dots: false,  
    responsiveClass: true,  
    responsive: {  
      300: { items: 3, nav: true },  
      400: { items: 4, nav: true },  
      600: { items: 6, nav: true }  
    }  
  });  

  var newItems = [  
    {  
      title: 'MJ X500',  
      imageUrl: 'https://blogger.googleusercontent.com/img/a/AVvXsEjEBpaO_D3wnTHbi0HOIVxGGEdViRszENPDNuJW7IVzJA2x0IGgNC3qxGTFMglqIlEK69cDAwb6pnkCiUHDte3CkVLhfbHnXuZl7Vkn-L0KkUZZv2b0Ot9jS-XvOUOKh6KrSTOd92u0N42z4l4AquarDdUigMO07Tc2l0f7hOi_283cMVtOH_tq1A_ZpnXS',   
      launchUrl: '/game/pgs/3',   
      promo: true   
    },  
    {  
      title: 'Petir X5000',  
      imageUrl: 'https://blogger.googleusercontent.com/img/a/AVvXsEgDm3jIeaxizYZ-UIaA4Hba13SJAI300WYrrTUx3n-vSxee7z0TkH57Ne24SUnoIWepAtky2WorCly_WE9WyIi_HQ5Iztonpam7XzBxGshZXcV1uYBOzKBUNJ0H04h_HlS80g5aSg94jkurYpNVtgzlvEsGV5hO4JioYI44V6pt0DB4dYDmH-5rhD67_ebl',   
      launchUrl: '/game/pgs/3',   
      promo: true   
    },  
    {  
      title: 'Petir X5000',  
      imageUrl: 'https://blogger.googleusercontent.com/img/a/AVvXsEgDm3jIeaxizYZ-UIaA4Hba13SJAI300WYrrTUx3n-vSxee7z0TkH57Ne24SUnoIWepAtky2WorCly_WE9WyIi_HQ5Iztonpam7XzBxGshZXcV1uYBOzKBUNJ0H04h_HlS80g5aSg94jkurYpNVtgzlvEsGV5hO4JioYI44V6pt0DB4dYDmH-5rhD67_ebl',   
      launchUrl: '/game/pgs/3',   
      promo: true   
    }, 
  ];  

  newItems.forEach(function (item, index) {  
    var promoLabel = item.promo ? '<div style="position:absolute; top:0; left:0; background-color:red; color:white; padding:2px 5px; font-size:12px; z-index:1000; animation: blink 1s infinite;">NEW</div>' : ''; 
     
    var newItem =   
      `<div class="owl-item" style="width: 98.333px;">  
        <div class="item" style="position:relative; display:flex; flex-direction:column; align-items:center;">  
          ${promoLabel}  
          <a href="${item.launchUrl}" class="nav-link" style="display: flex; flex-direction: column; align-items: center;">  
            <img src="${item.imageUrl}" alt="${item.title}" style="width:50px;height:50px;"/>  
            <span style="margin-top:5px;">${item.title}</span>  
          </a>  
        </div>  
      </div>`;  

    gmfr.trigger('add.owl.carousel', [$(newItem), index + 0]).trigger('refresh.owl.carousel');  
  });  

  gmfr.find("a").on("click", function (e) {  
    var _this = $(this);  
    var target = _this.attr("href");  

    if (target.startsWith("/")) {  
      e.preventDefault();  

      window.location.href = target;  
    }  
  });

  // Add the new HTML below the .game-front-menu
  var additionalContent = `
    <div style="margin: 0 auto; width: 100%; overflow: hidden; display: flex; justify-content: center;">
        <a href="/game/pgr/3" target="_blank" style="flex: 1; margin-right: 4px;">
            <img src="https://pub-59807136fda14e94acb50bfd28c448e8.r2.dev/fb-CAFE69.gif" style="width: 100%; height: auto; border: none;">
        </a>
        <a href="/game/pgr/3" target="_blank" style="flex: 1;">

            <img src="https://pub-59807136fda14e94acb50bfd28c448e8.r2.dev/fb-CAFE69.gif" style="width: 100%; height: auto; border: none;">
        </a>
    </div>
  `;

  // Append the additional content after .game-front-menu
  $('.game-front-menu').after(additionalContent);  
});

</script>