<?php
use App\Models\GameApi;
?>
@auth
<div class="container wallet-bal">
  <div class="row text-left">
    <div class="col-xs-6">
      <button class="btn btn-clear btn-refresh-wallet">
        <i class="icon-currency-dollar fs-lg i-dollar"></i>
        &nbsp;&nbsp;

        <span class="bal-txt"><img src="{{ asset('images/loader.gif') }}" alt="Loader" width="32" height="32"></span>
      </button>
    </div>
    <div class="col-xs-6 noSidePadding i-refresh">
      <button class="btn btn-clear btn-refresh-wallet pull-right"><i class="icon-refresh-2"></i></button>
    </div>
  </div>
</div>

<script type="text/javascript">

  $(document).ready(function() {
    // Panggil fungsi untuk memuat saldo saat halaman dimuat
    loadBalance();

    // Fungsi untuk memuat saldo dengan AJAX
    function loadBalance() {
      $.ajax({
        type: 'GET',
        url: '/getBal',
        dataType: 'json',
        success: function(response) {
          // Periksa apakah respons memiliki data saldo
          if (response.data) {
            $('.bal-txt').text(response.data);
          } else {
            $('.bal-txt').text('IDR 0.00');
          }
        },
        error: function(xhr, status, error) {
          // Tangani kesalahan jika permintaan gagal
          console.error('Failed to load balance:', error);
        }
      });
    }

  });
</script>
@endauth