<?php $__env->startSection('content'); ?>
  <?php
    $totalPlayed = $gameplayhistory->sum(fn ($history) => (float) $history->playedamount);
    $totalAdded = $wallethistory->sum(fn ($history) => (float) $history->addamount);
    $totalWithdrawn = $withdrawhistory->sum(fn ($history) => (float) $history->withdrawamt);
    $renderStatusBadge = function ($status) {
        return match ((int) $status) {
            1 => ['label' => 'Approved', 'class' => 'badge-success'],
            2 => ['label' => 'Pending', 'class' => 'badge-warning'],
            3 => ['label' => 'Cancelled', 'class' => 'badge-danger'],
            default => ['label' => 'Unknown', 'class' => 'badge-secondary'],
        };
    };
  ?>

  <div class="card-header">
    <h4>Student Payment History</h4>
  </div>
  <div class="card-body">
    <?php echo $__env->make('admin.partials.flash-messages', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?>

    <div class="payment-history-summary">
      <div class="payment-history-card">
        <span>Student</span>
        <strong><?php echo e($student->name); ?></strong>
      </div>
      <div class="payment-history-card">
        <span>Competition Spend</span>
        <strong>Rs. <?php echo e(number_format($totalPlayed, 2)); ?></strong>
      </div>
      <div class="payment-history-card">
        <span>Wallet Credits</span>
        <strong>Rs. <?php echo e(number_format($totalAdded, 2)); ?></strong>
      </div>
      <div class="payment-history-card">
        <span>Total Withdraw</span>
        <strong>Rs. <?php echo e(number_format($totalWithdrawn, 2)); ?></strong>
      </div>
    </div>

    <div class="payment-history-section">
      <div class="payment-history-section-head">
        <h5>Competition Played Details</h5>
        <span><?php echo e(number_format($gameplayhistory->count())); ?> record<?php echo e($gameplayhistory->count() === 1 ? '' : 's'); ?></span>
      </div>
      <div class="table-responsive">
        <table class="table table-striped table-hover" id="tableExport" style="width:100%;">
          <thead>
            <tr>
              <th>S.No.</th>
              <th>Competition Title</th>
              <th>Competition Amount</th>
              <th>Applied Time</th>
            </tr>
          </thead>
          <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $gameplayhistory; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $history): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
              <tr>
                <td><?php echo e($loop->iteration); ?></td>
                <td><?php echo e($history->assignment?->competitiontitle ?: ($history->contestname ?: $history->contest?->contesttitile)); ?></td>
                <td>Rs. <?php echo e(number_format((float) $history->playedamount, 2)); ?></td>
                <td><?php echo e($history->createtime?->format('d-m-Y h:i:s A') ?? '-'); ?></td>
              </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
              <tr>
                <td colspan="4" class="payment-history-empty-cell">No competition payment history found.</td>
              </tr>
            <?php endif; ?>
          </tbody>
        </table>
      </div>
    </div>

    <div class="payment-history-section">
      <div class="payment-history-section-head">
        <h5>Wallet Credit Details</h5>
        <span><?php echo e(number_format($wallethistory->count())); ?> record<?php echo e($wallethistory->count() === 1 ? '' : 's'); ?></span>
      </div>
      <div class="table-responsive">
        <table class="table table-striped table-hover" style="width:100%;">
          <thead>
            <tr>
              <th>S.No.</th>
              <th>Deposit Amount</th>
              <th>Transaction ID</th>
              <th>Status</th>
              <th>Deposit Date</th>
            </tr>
          </thead>
          <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $wallethistory; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $history): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
              <?php ($statusMeta = $renderStatusBadge($history->status)); ?>
              <tr>
                <td><?php echo e($loop->iteration); ?></td>
                <td>Rs. <?php echo e(number_format((float) $history->addamount, 2)); ?></td>
                <td><?php echo e($history->transectionid ?: '-'); ?></td>
                <td><span class="badge <?php echo e($statusMeta['class']); ?>"><?php echo e($statusMeta['label']); ?></span></td>
                <td><?php echo e($history->createdtime?->format('d-m-Y h:i:s A') ?? '-'); ?></td>
              </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
              <tr>
                <td colspan="5" class="payment-history-empty-cell">No wallet credit history found.</td>
              </tr>
            <?php endif; ?>
          </tbody>
        </table>
      </div>
    </div>

    <div class="payment-history-section">
      <div class="payment-history-section-head">
        <h5>Withdraw Details</h5>
        <span><?php echo e(number_format($withdrawhistory->count())); ?> record<?php echo e($withdrawhistory->count() === 1 ? '' : 's'); ?></span>
      </div>
      <div class="table-responsive">
        <table class="table table-striped table-hover" style="width:100%;">
          <thead>
            <tr>
              <th>S.No.</th>
              <th>Withdraw Amount</th>
              <th>Payment Type</th>
              <th>Mobile Number</th>
              <th>Status</th>
              <th>Request Date</th>
            </tr>
          </thead>
          <tbody>
            <?php $__empty_1 = true; $__currentLoopData = $withdrawhistory; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $history): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
              <?php ($statusMeta = $renderStatusBadge($history->status)); ?>
              <tr>
                <td><?php echo e($loop->iteration); ?></td>
                <td>Rs. <?php echo e(number_format((float) $history->withdrawamt, 2)); ?></td>
                <td><?php echo e($history->paymenttype ?: '-'); ?></td>
                <td><?php echo e($history->mobilenumber ?: '-'); ?></td>
                <td><span class="badge <?php echo e($statusMeta['class']); ?>"><?php echo e($statusMeta['label']); ?></span></td>
                <td><?php echo e($history->createdtime?->format('d-m-Y h:i:s A') ?? '-'); ?></td>
              </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
              <tr>
                <td colspan="6" class="payment-history-empty-cell">No withdraw history found.</td>
              </tr>
            <?php endif; ?>
          </tbody>
        </table>
      </div>
    </div>
  </div>

<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.admin', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\examproject\examproject_new\resources\views/admin/school/userpayments.blade.php ENDPATH**/ ?>