<?php
   require $_SERVER["DOCUMENT_ROOT"].'/inc/topo.php';
   require $_SERVER["DOCUMENT_ROOT"].'/inc/menu.php';
   require $_SERVER["DOCUMENT_ROOT"].'/api/pages/ver-mapa.php';
   requerPermissao('8');
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
   <!-- Content Header (Page header) -->
   <section class="content-header">
      <center>
        <table>
          <tr>
            <td align="center"><b><?php echo $api['team1']; ?></b> &nbsp; <img width="50" src="<?php echo $api['team1_img']; ?>" alt=""></td>
            <td align="center" width="50"><i class="fa fa-times"></i></td>
            <td align="center"><img width="50" src="<?php echo $api['team2_img']; ?>" alt=""> &nbsp; <b><?php echo $api['team2']; ?></b></td>
          </tr>
        </table>
      </center>
   </section>
   <!-- Main content -->
   <section class="content">
      <div class="row">
         <div class="col-12">
            <div class="box box-solid bg-black">
               <div class="box-header">
                  <h4 class="box-title"><strong class="event-strong">Detalhes da partida</strong></h4>
               </div>
               <div class="box-content">
                  <div class="box-body">
                    <div class="row">
                      <div class="col-12 col-md-4 col-xl-4">
                        <a class="box text-center">
                          <div class="box-body py-25">
                            <p class="font-size-40">
                              <strong><?php echo $api['match_date']; ?></strong>
                            </p>
                            <p class="font-weight-600">Data</p>
                          </div>
                        </a>
                      </div>
                      <div class="col-12 col-md-4 col-xl-4">
                        <a class="box text-center">
                          <div class="box-body py-25">
                            <p class="font-size-40">
                              <strong>R$<?php echo $api['price']; ?></strong>
                            </p>
                            <p class="font-weight-600">Apostado</p>
                          </div>
                        </a>
                      </div>
                      <div class="col-12 col-md-4 col-xl-4">
                        <a class="box text-center">
                          <div class="box-body py-25">
                            <p class="font-size-40">
                              <strong><?php echo $api['qtd']; ?></strong>
                            </p>
                            <p class="font-weight-600">Bilhetes</p>
                          </div>
                        </a>
                      </div>

                    </div>
                  </div>
               </div>
            </div>

            <div class="box box-solid bg-black">
               <div class="box-header">
                  <h4 class="box-title"><strong class="event-strong">Bilhetes</strong></h4>
               </div>
               <div class="box-content">
                  <div class="box-body">
                    <div class="row">
                      <?php foreach ($api['status'] as $s => $v) {
                          $status = '';
                          $class = '';
                          switch ($s) {
                            case '1':
                              $class = 'info';
                              $status = 'Em aberto';
                              break;

                            case '2':
                              $class = 'success';
                              $status = 'Ganhou';
                              break;

                            case '3':
                              $class = 'danger';
                              $status = 'Perdeu';
                              break;

                            case '4':
                              $class = 'navy';
                              $status = 'Cancelado';
                              break;

                            default:
                              $class = 'warning';
                              $status = 'Indefinido';
                              break;
                          }
                        ?>
                        <div class="col-12 col-md-3 col-sm-3 col-lg-3" style="text-align: center;">
                          <div class="box-body py-25">
                            <p class="font-size-40 text-<?php echo $class; ?>">
                              <strong>R$<?php echo $v['price']; ?></strong>
                            </p>
                            <p class="font-weight-600"><?php echo $status; ?></p>
                          </div>
                        </div>
                      <?php } ?>
                    </div>
                  </div>
               </div>
            </div>

            <div class="box box-solid bg-black">
               <div class="box-header">
                  <h4 class="box-title"><strong class="event-strong">Opções apostadas</strong></h4>
               </div>
               <div class="box-content">
                  <div class="box-body">
                     <div class="table-responsive">

                        <table id="example" class="table table-bordered table-hover display nowrap margin-top-10 w-p100">
                           <thead>
                              <tr>
                                 <th width="60">-</th>
                                 <th>Mercado</th>
                                 <th>Opção</th>
                                 <th width="120">Valor</th>
                                 <th width="80">Quant.</th>
                              </tr>
                           </thead>
                           <tbody>
                              <?php
                                 $aux = 1;
                                 if(isset($api["error"])){
                                    echo '<tr><td colspan="6" align="center"><div class="callout callout-danger"> <h4>OOPS!</h4> <p>'.$api["error"].'</p> </div></td></tr>';
                                 } else {
                                 foreach ($api['options'] as $i => $v) {
                              ?>
                              <tr>
                                 <td align="center"><?php echo $aux; ?></td>
                                 <td><?php echo ($v["market"]); ?></td>
                                 <td align="center"><b><?php echo ($v["name"]); ?></b></td>
                                 <td align="center"><b href="#">R$<?php echo ($v["price"]); ?></b></td>
                                 <td align="center" class="text-info"><b class=""><?php echo $v["qtd"]; ?></b></td>
                              </tr>
                              <?php $aux++; } } ?>
                           </tbody>
                        </table>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>
      <!-- /.row -->
   </section>
   <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<!-- ./wrapper -->
<?php require $_SERVER["DOCUMENT_ROOT"].'/inc/rodape.php'; ?>
<!-- DataTables -->
<script src="/assets/vendor_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="/assets/vendor_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/media/js/jquery.dataTables.min.js"></script>
<script src="/assets/vendor_components/bootstrap-daterangepicker/daterangepicker.js"></script>
<script src="/assets/vendor_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
<script> $(function(){ $('[id="datepicker"]').datepicker({ autoclose: true, format: 'yyyy-mm-dd' }); }); </script>
<!-- start - This is for export functionality only -->
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/dataTables.buttons.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.flash.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/jszip.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/pdfmake.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/vfs_fonts.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.html5.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.print.min.js"></script>
<!-- end - This is for export functionality only -->
<!-- Unique_Admin for Data Table -->
<script src="/js/pages/data-table.js"></script>
<script src="/js/moneymask.js"></script>
<script>
    let input = document.getElementsByTagName('input')[0];

    // configuration
    SimpleMaskMoney.args = {
        prefix: '',
        suffix: '',
        fixed: true,
        fractionDigits: 2,
        decimalSeparator: ',',
        thousandsSeparator: '.',
        autoCompleteDecimal: false
    };

    // Your send method
    send = (e) => {
        if (e.key !== "Enter") return;
        // This method return value of your input in format number to save in your database
        SimpleMaskMoney.formatToNumber(input.value);
    }

    $(function(){
      $(document).ready(function(){

         $('[id="secondaryBlock"]').click(function(){
            var u = $(this).attr('data-usuario');
            $('.btnStatusUser'+u).click();
         });

         $('[id="changeSaldo"]').click(function(){
            var btn = $(this);
            btn.toggleClass('btn-info btn-success').find('i').attr('class', 'fa fa-spinner fa-spin');
            var user = btn.attr('data-usuario');
            var balance = $('#saldo-'+user).val();

            $.get('/api/changeBalance?user='+user+'&balance='+balance, function(data){
               var info = $.parseJSON(data);
               if(info.error != undefined){
                  alert(info.error);
                  btn.toggleClass('btn-info btn-success').find('i').attr('class', 'fa fa-check');
               }
               else if(info.success != undefined){
                  btn.toggleClass('btn-info btn-success').find('i').attr('class', 'fa fa-check');
                  $('#saldo-'+user).css('background', '#14b56f47');


                  $.toast({
                     heading: 'Pronto!',
                     text: 'O crédito foi alterado com sucesso.',
                     position: 'top-right',
                     loaderBg: '#FFF',
                     icon: 'success',
                     hideAfter: 3500,
                     stack: 6
                  });
               }
            });
         });

         $('[id="changeStatus"]').click(function(){
            var btn = $(this);
            var btn_content = btn.html();
            btn.toggleClass('btn-danger btn-success').html('<i class="fa fa-spinner fa-spin"></i>');
            var user = btn.attr('data-usuario');

            $.get('/api/changeStatus?user='+user, function(data){
               var info = $.parseJSON(data);
               if(info.error != undefined){
                  alert(info.error);
                  btn.toggleClass('btn-info btn-success').html(btn_content);
               }
               else if(info.success != undefined){
                  if(info.user_status == '1'){
                     btn.html('Ativo');
                  } else {
                     btn.html('Inativo');
                  }

                 $.toast({
                     heading: 'Pronto!',
                     text: 'O status foi alterado com sucesso.',
                     position: 'top-right',
                     loaderBg: '#FFF',
                     icon: 'success',
                     hideAfter: 3500,
                     stack: 6
                 });

               }
            });
         });

      });
    });
</script><?php
   require $_SERVER["DOCUMENT_ROOT"].'/inc/topo.php';
   require $_SERVER["DOCUMENT_ROOT"].'/inc/menu.php';
   require $_SERVER["DOCUMENT_ROOT"].'/api/pages/mapa.php';
   requerPermissao('8');
?>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
   <!-- Content Header (Page header) -->
   <section class="content-header">
      <h1>
         Mapa de Apostas
         <small>Gerenciamento de Banca</small>
      </h1>
   </section>
   <!-- Main content -->
   <section class="content">
      <div class="row">
         <div class="col-12">
            <div class="box box-solid bg-black">
               <div class="box-header">
                  <h4 class="box-title"><strong class="event-strong">Mapa de Apostas</strong></h4>
               </div>
               <div class="box-content">
                  <div class="box-body">
                     <div class="table-responsive">

                        <table id="example" class="table table-bordered table-hover display nowrap margin-top-10 w-p100">
                           <thead>
                              <tr>
                                 <th width="60">-</th>
                                 <th>Partida</th>
                                 <th width="120">Valor</th>
                                 <th width="80">Quant.</th>
                                 <th width="200">Opções</th>
                              </tr>
                           </thead>
                           <tbody>
                              <?php
                                 if(isset($api["error"])){
                                    echo '<tr><td colspan="6" align="center"><div class="callout callout-danger"> <h4>OOPS!</h4> <p>'.$api["error"].'</p> </div></td></tr>';
                                 } else {
                                 foreach ($api['matches'] as $i => $v) {
                                  $i++;
                              ?>
                              <tr>
                                 <td align="center"><?php echo $i; ?></td>
                                 <td><?php echo strtoupper($v["name"]); ?></td>
                                 <td align="center"><b href="#">R$<?php echo ($v["price"]); ?></b></td>
                                 <td align="center" class="text-info"><b class=""><?php echo $v["qtd"]; ?></b></td>
                                 <td align="center">
                                    <a href="/gestao-de-apostas/ver-mapa/<?php echo $v['code']; ?>" class="btn btn-sm btn-warning ">Selecionar &nbsp; <i class="fa fa-caret-right"></i></a>
                                 </td>
                              </tr>
                              <?php } } ?>
                           </tbody>
                        </table>
                     </div>
                  </div>
               </div>
            </div>
         </div>
      </div>
      <!-- /.row -->
   </section>
   <!-- /.content -->
</div>
<!-- /.content-wrapper -->
<!-- ./wrapper -->
<?php require $_SERVER["DOCUMENT_ROOT"].'/inc/rodape.php'; ?>
<!-- DataTables -->
<script src="/assets/vendor_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="/assets/vendor_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/media/js/jquery.dataTables.min.js"></script>
<script> $(function(){ $('[id="datepicker"]').datepicker({ autoclose: true, format: 'yyyy-mm-dd' }); }); </script>
<!-- start - This is for export functionality only -->
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/dataTables.buttons.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.flash.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/jszip.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/pdfmake.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/ex-js/vfs_fonts.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.html5.min.js"></script>
<script src="/assets/vendor_plugins/DataTables-1.10.15/extensions/Buttons/js/buttons.print.min.js"></script>
<!-- end - This is for export functionality only -->
<!-- Unique_Admin for Data Table -->
<script src="/js/pages/data-table.js"></script>