<?php $__env->startSection('content'); ?>

<div class="card mb-3">
  <div class="card-header">
    <div class="row flex-between-end">
      <div class="col-auto align-self-center">
        <a href="<?php echo e(url('/member_profile', $member->id)); ?>" class="btn btn-primary btn-sm">
          <i class="fas fa-arrow-circle-left"></i> Back
        </a> <!-- Button to trigger modal -->
        <button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#uploadKycModal">
          <i class="fas fa-upload"></i> Upload KYC Document
        </button>

        <br><br>
        <h5 class="mb-0">KYC Documents for <?php echo e($member->name); ?> <?php echo e($member->surname); ?></h5>
      </div>
    </div>
  </div>

  <div class="card-body pt-0">
    <div id="tableExample2" data-list='{"valueNames":["document_type","status","id"],"page":10,"pagination":true}'>
      <div class="table-responsive scrollbar">
        <table class="table table-bordered table-striped fs--1 mb-0">
          <thead class="bg-200 text-900">
            <tr>
              <th class="sort" data-sort="document_type">Document Type</th>
              <th class="sort" data-sort="status">Status</th>
              <th class="sort" data-sort="remarks">Remarks</th>
              <th>File</th>
              <th>Action</th>
            </tr>
          </thead>
          <tbody class="list">
            <?php $__currentLoopData = $kycDocuments; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $document): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <tr>
              <td class="document_type"><?php echo e($document->document_type); ?></td>
              <td class="status">
                <span class="badge 
                                    <?php echo e($document->status == 'verified' ? 'bg-success' : 
                                       ($document->status == 'pending' ? 'bg-warning' : 'bg-danger')); ?>">
                  <?php echo e(ucfirst($document->status)); ?>

                </span>
              </td>
              <td class="remarks"><?php echo e($document->remarks ?? 'N/A'); ?></td>
              <td>
                <a href="<?php echo e(asset($document->document_path)); ?>" target="_blank" class="btn btn-info btn-sm">
                  <i class="fas fa-eye"></i> View
                </a>
              </td>

              <td>
                <!-- Remark Update (Allowed for Everyone) -->
                <form action="<?php echo e(route('kyc.updateStatus', $document->id)); ?>" method="POST" style="display:inline;">
                  <?php echo csrf_field(); ?>

                  <!-- Remark Input (Visible to Everyone) -->
                  <input type="text" name="remarks" placeholder="Add remarks" class="form-control form-control-sm" value="<?php echo e($document->remarks); ?>">

                  <?php if(Auth::user()->role == 3): ?> <!-- Only Admins Can Change Status -->
                  <select name="status" class="form-select form-select-sm mt-1">
                    <option value="pending" <?php echo e($document->status == 'pending' ? 'selected' : ''); ?>>Pending</option>
                    <option value="verified" <?php echo e($document->status == 'verified' ? 'selected' : ''); ?>>Verified</option>
                    <option value="rejected" <?php echo e($document->status == 'rejected' ? 'selected' : ''); ?>>Rejected</option>
                  </select>
                  <?php endif; ?>

                  <button type="submit" class="btn btn-sm btn-success mt-1">
                    <i class="fas fa-check"></i> Update
                  </button>
                </form>

                <?php if(Auth::user()->role == 3): ?> <!-- Only Admins Can Delete -->
                <!-- Delete Button -->
                <form action="<?php echo e(route('kyc.destroy', $document->id)); ?>" method="POST" style="display:inline;">
                  <?php echo csrf_field(); ?>
                  <?php echo method_field('DELETE'); ?>
                  <button type="submit" class="btn btn-sm btn-danger mt-1" onclick="return confirm('Are you sure?')">
                    <i class="far fa-trash-alt"></i> Delete
                  </button>
                </form>
                <?php endif; ?>
              </td>

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

      <div class="d-flex justify-content-center mt-3">
        <button class="btn btn-sm btn-falcon-default me-1" type="button" title="Previous" data-list-pagination="prev">
          <span class="fas fa-chevron-left"></span>
        </button>
        <ul class="pagination mb-0"></ul>
        <button class="btn btn-sm btn-falcon-default ms-1" type="button" title="Next" data-list-pagination="next">
          <span class="fas fa-chevron-right"></span>
        </button>
      </div>
    </div>
  </div>
</div>

<!-- Upload KYC Document Modal -->
<div class="modal fade" id="uploadKycModal" tabindex="-1" aria-labelledby="uploadKycModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="uploadKycModalLabel">Upload KYC Document</h5>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <form action="<?php echo e(route('kyc.store', $member->id)); ?>" method="POST" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>
        <div class="modal-body">
          <div class="mb-3">
            <label for="document_type" class="form-label">Document Type</label>
            <select class="form-select" name="document_type" required>
              <option value="">Select Type</option>
              <option value="National ID">National ID</option>
              <option value="Passport">Passport</option>
              <option value="Utility Bill">Utility Bill</option>
              <option value="Bank Statement">Bank Statement</option>
              <option value="Marriage Certificate">Marriage Certificate</option>
              <option value="Birth Certificate">Birth Certificate</option>
            </select>

          </div>

          <div class="mb-3">
            <label for="document_file" class="form-label">Upload Document</label>
            <input type="file" class="form-control" name="document_file" accept=".pdf,.jpg,.png,.jpeg" required>
            <small class="text-muted">Allowed formats: PDF, JPG, PNG (Max: 2MB)</small>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
          <button type="submit" class="btn btn-primary"><i class="fas fa-upload"></i> Upload</button>
        </div>
      </form>
    </div>
  </div>
</div>

<?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/kyc/index.blade.php ENDPATH**/ ?>