 <?php $__env->startSection('content'); ?>
<div class="card mb-3">
  <div class="card-body pt-0">
    <div class="row">
      <!-- Search by Date -->
      <div class="col-lg-6 pt-3 pt-lg-0">
        <div class="d-flex flex-between-center mb-3">
          <div class="d-flex align-items-center">
            <div class="icon-item icon-item-sm bg-soft-primary shadow-none me-2 bg-soft-success">
              <span class="fas fa-calendar-week text-success"></span>
            </div>
            <h6 class="mb-0">Search Per Date</h6>
          </div>
        </div>
        <form class="form-material" method="POST" action="<?php echo e(url('/search_date_member')); ?>">
          <?php echo csrf_field(); ?>
          Cover:
          <select required name="cover" class="form-control">
            <option value="" disabled selected>--Select Option--</option>
            <option>All</option>
            <?php $__currentLoopData = $covers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cover1): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($cover1->id); ?>"><?php echo e($cover1->name); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </select>
          <br>
          Start Date:
          <input type="date" value="<?php echo e(date('Y-m-d')); ?>" required class="form-control" name="date1"><br>
          End Date:
          <input type="date" value="<?php echo e(date('Y-m-d')); ?>" required class="form-control" name="date2">
          <br>
          <button type="submit" class="btn btn-primary btn-sm"><i class="fas fa-search"></i> Preview</button>
        </form>
      </div>

      <!-- Search by Group -->
      <div class="col-lg-6 pt-3 pt-lg-0">
        <div class="d-flex flex-between-center mb-3">
          <div class="d-flex align-items-center">
            <div class="icon-item icon-item-sm bg-soft-primary shadow-none me-2 bg-soft-info">
              <span class="fas fa-users text-info"></span>
            </div>
            <h6 class="mb-0">Search Per Group</h6>
          </div>
        </div>
        <form class="form-material" method="POST" action="<?php echo e(url('/search_group_member')); ?>">
          <?php echo csrf_field(); ?>
          Group:
          <select required name="group_id" class="form-control">
            <option value="" disabled selected>--Select Group--</option>

            <?php $__currentLoopData = $groups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $group): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <option value="<?php echo e($group->id); ?>"><?php echo e($group->name); ?></option>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </select>
          <br>
          Start Date:
          <input type="date" name="date1" value="<?php echo e(date('Y-m-d')); ?>" class="form-control" required><br>
          End Date:
          <input type="date" name="date2" value="<?php echo e(date('Y-m-d')); ?>" class="form-control" required><br>

          <button type="submit" class="btn btn-info btn-sm"><i class="fas fa-search"></i> Preview</button>
        </form>
      </div>

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

<div class="card mb-3">
  <div class="card-header">
    <div class="row flex-between-end">
      <div class="col-auto align-self-center">
        <form class="form-material" method="POST" action="<?php echo e(url ('/search_member')); ?>">
          <?php echo csrf_field(); ?>
          <input type="text" required class="form-control" placeholder="Search by National ID" name="search" id="search">
          <br><button type="submit" class="btn btn-primary btn-sm" aria-placeholder="Search"><i class="fas fa-search"></i> Advanced Search</button>
        </form>
      </div>

      <div class="col-auto align-self-center">
        <form class="form-material" method="POST" action="<?php echo e(url ('/search_member2')); ?>">
          <?php echo csrf_field(); ?>
          <input type="text" required class="form-control" name="search" placeholder="Search by Cellphone number" id="search">
          <br><button type="submit" class="btn btn-primary btn-sm" aria-placeholder="Search"><i class="fas fa-search"></i> Advanced Search</button>
        </form>
      </div>

      <div class="col-auto align-self-center">
        <form class="form-material" method="POST" action="<?php echo e(url ('/search_member1')); ?>">
          <?php echo csrf_field(); ?>
          <input type="text" required class="form-control" name="search" placeholder="Search by Name" id="search">
          <br><button type="submit" class="btn btn-primary btn-sm" aria-placeholder="Search"><i class="fas fa-search"></i> Advanced Search</button>
        </form>
      </div>
    </div>
  </div>
  <div class="card-body pt-0">
    &nbsp;
    <!-- <a href="<?php echo e(url ('allstatus')); ?>" class="btn btn-success btn-sm"> Update Status</a>-->
    <br>
    <br>
    <h5 class="mb-0" data-anchor="data-anchor">List of all members</h5>
    <p>Displaying <?php echo e($members->count()); ?> of <?php echo e($members->total()); ?> members</p>
    <small>If you can find the member you are looking for, <br> please use the advanced search option.</small>
    <div class="dt-responsive table-sm table-responsive">
      <small>
        <table id="basic-btn" class="table table-sm text-sm table-striped table-bordered nowrap">
          <thead class="bg-200 text-900">
            <tr>
              <th>#</th>
              <th>Payment</th>
              <th>Name</th>
              <th>Surname</th>
              <th>Group</th>
              <th>Cover</th> <!-- New -->
              <th>Monthly Pay</th> <!-- New -->
              <th>National ID</th>
              <th>Cell Number</th>
              <th>Status</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody>
            <?php $__currentLoopData = $members; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $member): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php
            $isRestart = $member->status1 === "Restart";
            $canRestart = $isRestart && Auth::user()->role == 3;
            $rowClass = $member->deceased ? 'table-danger text-danger fw-bold' : ''; // 🔴 highlight deceased
            ?>
            <tr class="<?php echo e($rowClass); ?>">
              <td><?php echo e($loop->iteration); ?></td>
              <?php
              $shouldDisable = ($member->status1 === "Restart" && Auth::user()->role != 3);
              $disableStyle = $shouldDisable ? 'style="pointer-events:none; opacity:0.5;"' : '';
              ?>

              <!-- Payment & Profile buttons -->
              <td>
                
                <?php if(!$isRestart && optional($member->premiumPayments)->isNotEmpty()): ?>
                <a href="<?php echo e(url('/memberpayments', $member->id)); ?>" class="btn btn-primary btn-sm">
                  <i class="fas fa-money-check"></i> Payment
                </a>
                &nbsp;
                <?php endif; ?>
                <a href='<?php echo e(url("/member_profile", $member->id)); ?>' class="btn btn-primary btn-sm" <?php echo $disableStyle; ?>>
                  <i class="far fa-user-circle"></i> Profile
                </a>
              </td>
              <!-- Member Details -->
              <td><?php echo e($member->name); ?></td>
              <td><?php echo e($member->surname); ?></td>
              <td><?php echo e($member->group ? $member->group->name : 'N/A'); ?></td>

              <!-- Cover Name -->
              <td>
                <?php echo e(optional(optional($member->premium)->cover)->name ?? 'N/A'); ?>

              </td>

              <!-- Monthly Pay -->
              <td>
                <?php if(optional(optional($member->premium)->cover)->monthly_pay): ?>
                E<?php echo e(number_format($member->premium->cover->monthly_pay, 2)); ?>

                <?php else: ?>
                N/A
                <?php endif; ?>
              </td>

              <td><?php echo e($member->national_id); ?></td>
              <td><?php echo e($member->cell_number); ?></td>
              <td>
                <?php if($member->deceased): ?>
                <span class="badge bg-danger">Deceased</span>
                <?php else: ?>
                <span class="badge bg-success"><?php echo e($member->status1); ?></span>
                <?php endif; ?>
              </td>

              <!-- Action Buttons -->
              <td>
                &nbsp;
                <?php if(optional($member->premiumPayments)->isEmpty()): ?>
                <a href="<?php echo e(url('/member', $member->id)); ?>"
                  class="btn btn-primary btn-sm"
                  <?php echo $disableStyle; ?>>
                  <i class="far fa-edit"></i> Edit
                </a>
                <?php endif; ?>

                <?php if($member->status1 == "Restart" && Auth::user()->role == 3): ?>
                <a href='<?php echo e(url("/restart", $member->id)); ?>' class="btn btn-secondary btn-sm">
                  <i class="far fa-clock"></i> Restart
                </a>              
                <?php endif; ?>


              </td>
            </tr>
            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
          </tbody>
        </table>



      </small>
    </div>


  </div>

</div>

<script>
  var deleteLinks = document.querySelectorAll('.delete');

  for (var i = 0; i < deleteLinks.length; i++) {
    deleteLinks[i].addEventListener('click', function(event) {
      event.preventDefault();

      var choice = confirm(this.getAttribute('data-confirm'));

      if (choice) {
        window.location.href = this.getAttribute('href');
      }
    });
  }
</script>

<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\WORK-STATION\MBBS\Insurance-Version Controls\03-01-2026\resources\views/members/allmembers.blade.php ENDPATH**/ ?>