 
 <?php $__env->startSection('content'); ?>
<div class="card">
        <div class="card-header">
            <h6 class="card-title">Declare Result</h6>
        </div>
         <div class="card-body">
        
       </div>

        <!-- /.card-header -->
        <div class="card-body">
           
            
        <form action="<?php echo e(url('admin/declare-result')); ?>" method="POST">
            <?php echo csrf_field(); ?>

            <div class="row">

                <!-- Date -->
                <div class="col-md-4 mb-3">
                    <label><strong>Date</strong></label>
                    <input type="date" 
                           name="date" 
                           class="form-control"
                           value="<?php echo e(date('Y-m-d')); ?>">
                </div>

                <!-- Game -->
                <div class="col-md-4 mb-3">
                    <label><strong>Game</strong></label>
                    <select name="stores_id" class="form-control select2" required>
                        <option value="">Select an option</option>

                        <?php $__currentLoopData = $lists; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $game): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($game->id); ?>">
                                <?php echo e($game->name); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <!-- Session -->
                <div class="col-md-4 mb-3">
                    <label><strong>Session</strong></label>
                    <select name="type" class="form-control" required>
                        <option value="">Select Session</option>
                        <option value="open">Open</option>
                        <option value="close">Close</option>
                    </select>
                </div>

                <!-- Pana -->
                <div class="col-md-6 mb-3">
                    <label><strong>Pana</strong></label>
                    <select name="result" class="form-control select2" required>
                        <option value="">Select an Pana</option>

                        <?php $__currentLoopData = pannaList(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pana): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($pana); ?>">
                                <?php echo e($pana); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>

                <!-- Digit -->
                <div class="col-md-6 mb-3">
                    <label><strong>Digit</strong></label>
                    <input type="text" 
                           name="digit" 
                           class="form-control"
                           placeholder=""
                           id="digit_sum"
                           readonly
                           >
                </div>

                <!-- Save Button -->
                <div class="col-md-12 mt-2">
                    <button type="submit" class="btn btn-primary px-4" name="btn_type" value="declare_result">
                        Declare Result
                    </button>
                    <button type="button"
                            class="btn btn-info px-4"
                            id="show_winners">
                        Show Winners
                    </button>
                </div>

            </div>
        </form>
           
            <div id="example1_wrapper" class=" dt-bootstrap4 mt-4">
         
                <div class="row">
                    <div class="col-sm-12">
                          <div class='tablescroll'>
                            <div class="table-responsive">
                        <table id="example1" class="table table-bordered table-striped dataTable" role="grid"
                               aria-describedby="example1_info">
                            <thead>
                            <tr role="row">
                                <th class="sorting_asc" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-sort="ascending"
                                    aria-label="Rendering engine: activate to sort column descending"
                                    style="width: 60px;">S.No
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                    Game Name
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                   Result Date
                                </th>
                               
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                  Open Pana
                                </th>
                                <th class="sorting" tabindex="0" aria-controls="example1" rowspan="1" colspan="1"
                                    aria-label="Browser: activate to sort column ascending" style="width: 207px;">
                                  Close Pana
                                </th>
                              
                           
                                
                            </tr>
                            </thead>
                            <tbody>
                              <?php 
                    $page=1;
                    if(Request::input('page'))
                    $page=Request::input('page');
                    $sort = $lists->perPage();
                    $date = currentDate();
                  ?>
                  <?php $__empty_1 = true; $__currentLoopData = $lists; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $list): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                
                        <tr>
                          <td><?php echo e($sort*($page-1)+($key+1)); ?></td>
                          <td><?php echo e($list->name); ?></td>
                          <td><?php echo e(currentDate()); ?></td>
                          <td> 
                          
                          
                            <a><?php echo e($list->winner->open_time ?? 'xxx - x'); ?></a>
                            <br>
                            
                            <?php if(isset($list->winner) && isset($list->winner->open_time)): ?>
                            <div class="d-flex">
                             <a onclick="showResultWinners(<?php echo e($list->id); ?>,'open',<?php echo e(explode('-', $list->winner->open_time)[0]); ?>,<?php echo e($date); ?>)" class="btn btn-primary btn-sm text-white">Show Winners</a>
                             <form method="POST"
                                  action="<?php echo e(url('admin/gamwinnerrevers/'.$list->id)); ?>"
                                  onsubmit="return confirm('Are you sure you want to delete this result?');">
                                <?php echo csrf_field(); ?>
                            
                                <button type="submit" class="btn btn-primary btn-sm text-white">
                                    Delete Result
                                </button>
                            </form>
                            <form action="<?php echo e(url('admin/bid-revert-all')); ?>" method="POST">
                                 <?php echo csrf_field(); ?>
                                 <input type="hidden" name="stores_id" value="<?php echo e($list->id); ?>" />
                                 <input type="hidden" name="win" value="true" />
                                 <input type="hidden" name="type" value="open" />
                                 
                                 <button type="submit" class="btn btn-primary btn-sm text-white" name="type" value="revert_all"  onclick="return confirm('Are you sure you want to revert the all bets? This action cannot be undone.')">
                                    Bid Revert
                                </button>
                            </form>
                             </div>
                             <?php endif; ?>
                          <!--<?php if(isset($list->winner)): ?>-->
                          <!--  <a href="#" class="btn btn-primary"><?php echo e($list->winner->open_time); ?></a>-->
                            
                          <!--  <a href="<?php echo e(url('admin/reverseopenresult/'.$list->id)); ?>" class="btn btn-warning">Reverse Result </a>-->
                            
                          <!--      <a href="<?php echo e(url('admin/gamewinnerresult/'.$list->id)); ?>" class="btn btn-info"><i class="fa fa-eye" aria-hidden="true"></i> </a>-->
                          <!--<?php else: ?>-->
                          <!--  <a href="<?php echo e(url('admin/addopenresult/'.$list->id)); ?>" class="btn btn-info">Add Open Result </a>-->
                          <!--<?php endif; ?>-->
                          
                          </td>
                           <td> 
                           
                                <a><?php echo e($list->winner->close_time ?? 'x - xxx'); ?></a>
                            <br>
                            <?php if(isset($list->winner) && isset($list->winner->close_time) ): ?>
                            <div class="d-flex">
                             <a onclick="showResultWinners(<?php echo e($list->id); ?>,'close',<?php echo e(explode('-', $list->winner->close_time)[1]); ?>,<?php echo e($date); ?>)" class="btn btn-primary btn-sm text-white">Show Winners</a>
                                <form method="POST"
                                      action="<?php echo e(url('admin/gamwinnerreverseclose/'.$list->id)); ?>"
                                      onsubmit="return confirm('Are you sure you want to delete this result?');">
                                    <?php echo csrf_field(); ?>
                                
                                    <button type="submit" class="btn btn-primary btn-sm text-white">
                                        Delete Result
                                    </button>
                                </form>
                            <form action="<?php echo e(url('admin/bid-revert-all')); ?>" method="POST">
                                 <?php echo csrf_field(); ?>
                                 <input type="hidden" name="stores_id" value="<?php echo e($list->id); ?>" />
                                 <input type="hidden" name="win" value="true" />
                                 <input type="hidden" name="type" value="close" />
                                 
                                 <button type="submit" class="btn btn-primary btn-sm text-white" name="type" value="revert_all"  onclick="return confirm('Are you sure you want to revert the all bets? This action cannot be undone.')">
                                    Bid Revert
                                </button>
                            </form>
                             </div>
                             <?php endif; ?>
                          <!-- <?php if(isset($list->winner)): ?>-->
                          <!--  <?php if(isset($list->winner->close_time)): ?>-->
                          <!--      <a href="#" class="btn btn-primary"><?php echo e($list->winner->close_time); ?></a>-->
                                
                          <!--      <a href="<?php echo e(url('admin/reversecloseresult/'.$list->id)); ?>" class="btn btn-warning">Reverse Result </a>-->
                                
                          <!--          <a href="<?php echo e(url('admin/gamewinnerresultclose/'.$list->id)); ?>" class="btn btn-info"><i class="fa fa-eye" aria-hidden="true"></i> </a>-->
                          <!--    <?php else: ?>-->
                          <!--      <a href="<?php echo e(url('admin/addcloseresult/'.$list->id)); ?>" class="btn btn-info">Add Close Result </a>-->
                          <!--    <?php endif; ?>-->
                          
                          <!--<?php endif; ?>-->
                          
                           
                           </td>
                          
                        </tr>
                         <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                  <tr>
                    <td colspan="9">Record not found </td>
                  </tr>
                  <?php endif; ?>
                            </tbody>
                   </table>
                   </div>
                   </div>
                    <div class="row">
              <div class="col-md-6 text-left" style="margin: 20px 0px;">
                Showing  <?php echo e($lists->firstItem()); ?> to <?php echo e($lists->lastItem()); ?> of <?php echo e($lists->total()); ?>

              </div>
              <div class="col-md-6 text-right">
                <?php echo $lists->appends(request()->input())->links(); ?>

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

<div class="modal fade" id="winnerModal" tabindex="-1" role="dialog">
  <div class="modal-dialog modal-xl" role="document">
    <div class="modal-content">

      <div class="modal-header">
        <h5 class="modal-title">Winners</h5>
        <button type="button" class="close" data-dismiss="modal">&times;</button>
      </div>

      <div class="modal-body" id="winnerModalBody">
        <!-- AJAX content will load here -->
      </div>

    </div>
  </div>
</div>
 <?php $__env->stopSection(); ?>
<?php $__env->startSection('js-content'); ?>
<script>
$(document).on('change', 'select[name="result"]', function () {

    let val = $(this).val() || ""; // panna like 127

    let sum = 0;

    for (let i = 0; i < val.length; i++) {
        sum += parseInt(val[i]);
    }

    let lastDigit = sum % 10;

    $('#digit_sum').val(val ? lastDigit : '');
});

</script>
<script>
$('#show_winners').click(function () {

    $.ajax({
        url: "<?php echo e(url('admin/declare-result')); ?>",
        type: "POST",
        data: {
            _token: "<?php echo e(csrf_token()); ?>",
            date: $('[name="date"]').val(),
            stores_id: $('[name="stores_id"]').val(),
            type: $('[name="type"]').val(),
            result: $('[name="result"]').val(),
            digit: $('[name="digit"]').val(),
            btn_type: "show_winner"
        },
        beforeSend: function () {
            $('#winnerModalBody').html('<p>Loading...</p>');
            $('#winnerModal').modal('show');
        },
        success: function (response) {
            $('#winnerModalBody').html(response);
            $('#winnerModal').modal('show');
        },
        error: function () {
            $('#winnerModalBody').html('<p>Error loading data</p>');
        }
    });

});

</script>
<script>
function showResultWinners(stores_id,type,result,dateFilter) {

    $.ajax({
        url: "<?php echo e(url('admin/declare-result')); ?>",
        type: "POST",
        data: {
            _token: "<?php echo e(csrf_token()); ?>",
            stores_id:stores_id,
            type: type,
            result: result,
            btn_type: "show_winner"
        },
        beforeSend: function () {
            $('#winnerModalBody').html('<p>Loading...</p>');
            $('#winnerModal').modal('show');
        },
        success: function (response) {
            $('#winnerModalBody').html(response);
            $('#winnerModal').modal('show');
        },
        error: function () {
            $('#winnerModalBody').html('<p>Error loading data</p>');
        }
    });
}

</script>



<?php $__env->stopSection(); ?>
<?php echo $__env->make('admin.layouts.main-layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home/profcymadev/public_html/onebet.profcymadev.in/resources/views/admin/game-winner/index.blade.php ENDPATH**/ ?>