<?php $__env->startSection('content'); ?>
<div class="container-xxl flex-grow-1 container-p-y">
  <div class="card">
    <div class="card-header"><h5 class="mb-0"><?php echo e(($isSuperAdmin ?? false) ? 'All Referrals' : 'My Referrals'); ?></h5></div>

    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('view referral')): ?>
      <div class="table-responsive">
        <table <?php if($referrals->count() > 0): ?> id="referrals-table" <?php endif; ?> class="table">
          <thead>
            <tr>
              <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($isSuperAdmin ?? false): ?><th>Referrer</th><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
              <th>Code</th>
              <th>Referred User</th>
              <th>Reward</th>
              <th>Status</th>
              <th>Date</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
            <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php $__empty_1 = true; $__currentLoopData = $referrals; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $referral): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
            <tr>
              <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($isSuperAdmin ?? false): ?><td><?php echo e($referral->referrer->name ?? 'N/A'); ?></td><?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
              <td><?php echo e($referral->code); ?></td>
              <td><?php echo e($referral->referredUser->name ?? 'N/A'); ?></td>
              <td>$<?php echo e(number_format($referral->reward_amount,2)); ?></td>
              <td><?php echo e(ucfirst($referral->status)); ?></td>
              <td><?php echo e($referral->created_at->format('Y-m-d')); ?></td>
              <td>
                <?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if(auth()->check() && auth()->user()->hasRole('super admin')): ?>
                  <form method="POST" action="<?php echo e(route('admin.referrals.destroy', $referral)); ?>">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('DELETE'); ?>
                    <button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Delete this referral?')">Delete</button>
                  </form>
                <?php else: ?>
                  <span class="text-muted">-</span>
                <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
              </td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
            <tr><td colspan="<?php echo e(($isSuperAdmin ?? false) ? 7 : 6); ?>" class="text-center py-4">No referrals yet.</td></tr>
            <?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>
          </tbody>
        </table>
      </div>
    <?php else: ?>
      <div class="card-body"><div class="alert alert-warning mb-0">You do not have permission to view referrals.</div></div>
    <?php endif; ?>

    <div class="card-body"><?php echo e($referrals->links()); ?></div>
  </div>
</div>
<?php $__env->stopSection(); ?>

<?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if BLOCK]><![endif]--><?php endif; ?><?php if($referrals->count() > 0): ?>
<?php $__env->startPush('script'); ?>
<script>
$(document).ready(function () {
  const $table = $('#referrals-table');
  if (!$table.length) return;
  const dateColumnIndex = <?php echo e(($isSuperAdmin ?? false) ? 5 : 4); ?>;

  $table.DataTable({
    responsive: false,
    scrollX: true,
    pageLength: 10,
    lengthMenu: [5, 10, 25, 50, 100],
    order: [[dateColumnIndex, 'desc']],
    columnDefs: [{ orderable: false, targets: -1 }]
  });
});
</script>
<?php $__env->stopPush(); ?>
<?php endif; ?><?php if(\Livewire\Mechanisms\ExtendBlade\ExtendBlade::isRenderingLivewireComponent()): ?><!--[if ENDBLOCK]><![endif]--><?php endif; ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH F:\xampp\htdocs\G_desizn\marketplace\resources\views\referrals\index.blade.php ENDPATH**/ ?>