<?php $title = 'Pending Approvals - Ghana Anaesthesiologists Society'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <h1 class="h3 mb-0 text-white font-weight-bold"><i class="fas fa-clock mr-2"></i>Pending Membership Approvals</h1>
</div>
<?php if (!empty($users)): ?>
    <?php foreach ($users as $user): ?>
    <div class="glass-card mb-3">
        <div class="row align-items-center">
            <div class="col-lg-5">
                <h5 class="font-weight-bold"><?= htmlspecialchars($user->first_name ? trim($user->first_name . ' ' . $user->other_names . ' ' . $user->last_name) : $user->name) ?></h5>
                <p style="color: rgba(255,255,255,0.6); font-size: 0.9rem; margin: 0;">
                    <i class="fas fa-envelope mr-1"></i><?= htmlspecialchars($user->email) ?><br>
                    <?php if ($user->professional_pin): ?><i class="fas fa-id-badge mr-1"></i>PIN: <?= htmlspecialchars($user->professional_pin) ?><br><?php endif; ?>
                    <i class="fas fa-calendar mr-1"></i>Registered: <?= date('M d, Y H:i', strtotime($user->created_at)) ?>
                </p>
            </div>
            <div class="col-lg-7 mt-3 mt-lg-0">
                <div class="d-flex justify-content-end flex-wrap">
                    <a href="<?= $baseUrl ?>/users/<?= $user->id ?>/review" class="glass-btn mr-2 mb-2"><i class="fas fa-search mr-1"></i>Review</a>
                    <form method="POST" action="<?= $baseUrl ?>/users/<?= $user->id ?>/approve" style="display:inline;" onsubmit="return confirm('Approve this membership? An email notification will be sent.');">
                        <button type="submit" class="glass-btn glass-btn-success mr-2 mb-2"><i class="fas fa-check mr-1"></i>Approve</button>
                    </form>
                    <button type="button" class="glass-btn glass-btn-danger mb-2" data-toggle="modal" data-target="#rejectModal<?= $user->id ?>"><i class="fas fa-times mr-1"></i>Reject</button>
                </div>
            </div>
        </div>
    </div>

    <!-- Reject Modal -->
    <div class="modal fade" id="rejectModal<?= $user->id ?>" tabindex="-1">
        <div class="modal-dialog">
            <div class="modal-content glass-modal-content">
                <form method="POST" action="<?= $baseUrl ?>/users/<?= $user->id ?>/reject">
                    <div class="modal-header"><h5 class="modal-title">Reject Membership</h5><button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button></div>
                    <div class="modal-body">
                        <p>Reject membership for <strong><?= htmlspecialchars($user->first_name ? trim($user->first_name . ' ' . $user->last_name) : $user->name) ?></strong>?</p>
                        <div class="form-group">
                            <label style="color: rgba(255,255,255,0.7);">Reason (optional)</label>
                            <textarea name="rejection_reason" class="form-control glass-input" rows="3" placeholder="Provide a reason for rejection..."></textarea>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="glass-btn" data-dismiss="modal">Cancel</button>
                        <button type="submit" class="glass-btn glass-btn-danger">Reject</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <?php endforeach; ?>
<?php else: ?>
<div class="empty-state"><i class="fas fa-check-circle" style="color: #1cc88a;"></i><p>No pending approvals. All members have been reviewed.</p></div>
<?php endif; ?>
