<?php $title = 'Review Member - Ghana Anaesthesiologists Society'; ?>
<div class="d-sm-flex align-items-center justify-content-between mb-4">
    <div>
        <a href="<?= $baseUrl ?>/users/pending" class="glass-btn mb-3 d-inline-block"><i class="fas fa-arrow-left mr-1"></i>Back to Pending</a>
        <h1 class="h3 mb-0 text-white font-weight-bold"><i class="fas fa-search mr-2"></i>Review Membership Application</h1>
    </div>
</div>

<!-- User Summary -->
<div class="glass-card mb-4">
    <div class="row align-items-center">
        <div class="col-auto">
            <div style="width: 64px; height: 64px; border-radius: 50%; background: linear-gradient(135deg, #4e73df, #224abe); display: flex; align-items: center; justify-content: center;">
                <i class="fas fa-user-md text-white" style="font-size: 1.5rem;"></i>
            </div>
        </div>
        <div class="col">
            <h4 class="font-weight-bold mb-1"><?= htmlspecialchars(trim($user->first_name . ' ' . $user->other_names . ' ' . $user->last_name)) ?></h4>
            <p style="color: rgba(255,255,255,0.6); margin: 0;">
                <i class="fas fa-envelope mr-1"></i><?= htmlspecialchars($user->email) ?> &middot;
                <i class="fas fa-clock ml-2 mr-1"></i>Applied <?= date('M d, Y \a\t h:i A', strtotime($user->created_at)) ?>
            </p>
        </div>
        <div class="col-auto">
            <span class="glass-badge" style="background: rgba(246,194,62,0.2); color: #f6c23e; font-size: 0.85rem; padding: 0.4rem 1.2rem;">
                <i class="fas fa-clock mr-1"></i>Pending Review
            </span>
        </div>
    </div>
</div>

<div class="row">
    <!-- Personal Info -->
    <div class="col-lg-6 mb-4">
        <div class="glass-card h-100">
            <h5 class="font-weight-bold mb-3"><i class="fas fa-user mr-2" style="color: #4e73df;"></i>Personal Information</h5>
            <table class="table" style="color: rgba(255,255,255,0.8);">
                <tr><td style="border-color: rgba(255,255,255,0.05); width: 40%; color: rgba(255,255,255,0.5);">Full Name</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars(trim($user->first_name . ' ' . $user->other_names . ' ' . $user->last_name)) ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Email</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($user->email) ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Professional PIN</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($user->professional_pin ?: 'Not provided') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Medical Council No.</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($user->medical_council_number ?: 'Not provided') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Membership Category</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($user->membership_category ?: 'Not specified') ?></td></tr>
            </table>
        </div>
    </div>

    <!-- Account Info -->
    <div class="col-lg-6 mb-4">
        <div class="glass-card h-100">
            <h5 class="font-weight-bold mb-3"><i class="fas fa-cog mr-2" style="color: #858796;"></i>Account Details</h5>
            <table class="table" style="color: rgba(255,255,255,0.8);">
                <tr><td style="border-color: rgba(255,255,255,0.05); width: 40%; color: rgba(255,255,255,0.5);">Role</td><td style="border-color: rgba(255,255,255,0.05);"><span class="glass-badge"><?= htmlspecialchars(ucfirst($user->role)) ?></span></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Status</td><td style="border-color: rgba(255,255,255,0.05);"><span class="glass-badge" style="background: <?= $user->status === 'active' ? 'rgba(28,200,138,0.2)' : 'rgba(231,74,59,0.2)' ?>; color: <?= $user->status === 'active' ? '#1cc88a' : '#e74a3b' ?>;"><?= htmlspecialchars(ucfirst($user->status)) ?></span></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Registration Date</td><td style="border-color: rgba(255,255,255,0.05);"><?= date('F d, Y \a\t h:i A', strtotime($user->created_at)) ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Last Login</td><td style="border-color: rgba(255,255,255,0.05);"><?= $user->last_login ? date('F d, Y h:i A', strtotime($user->last_login)) : 'Never' ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Approval Status</td><td style="border-color: rgba(255,255,255,0.05);"><span class="glass-badge" style="background: rgba(246,194,62,0.2); color: #f6c23e;"><?= htmlspecialchars(ucfirst($user->approval_status)) ?></span></td></tr>
            </table>
        </div>
    </div>
</div>

<!-- Member Profile Section -->
<?php if ($profile): ?>
<div class="glass-card mb-4">
    <h5 class="font-weight-bold mb-3"><i class="fas fa-id-card mr-2" style="color: #1cc88a;"></i>Member Profile Details</h5>
    <div class="row">
        <div class="col-md-6">
            <table class="table" style="color: rgba(255,255,255,0.8);">
                <tr><td style="border-color: rgba(255,255,255,0.05); width: 40%; color: rgba(255,255,255,0.5);">Gender</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars(ucfirst($profile->gender ?: 'Not specified')) ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Nationality</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->nationality ?: 'Not specified') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Mobile Phone</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->mobile_phone ?: 'Not provided') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Alternative Phone</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->alternative_phone ?: 'Not provided') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Institution/Hospital</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->institution_hospital ?: 'Not specified') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">City/Town</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->city_town ?: 'Not specified') ?></td></tr>
            </table>
        </div>
        <div class="col-md-6">
            <table class="table" style="color: rgba(255,255,255,0.8);">
                <tr><td style="border-color: rgba(255,255,255,0.05); width: 40%; color: rgba(255,255,255,0.5);">Country</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->country ?: 'Not specified') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Highest Qualification</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->highest_qualification ?: 'Not specified') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Years of Practice</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->years_practice ?: 'Not specified') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Postal Address</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->postal_address ?: 'Not provided') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Residential Address</td><td style="border-color: rgba(255,255,255,0.05);"><?= htmlspecialchars($profile->residential_address ?: 'Not provided') ?></td></tr>
                <tr><td style="border-color: rgba(255,255,255,0.05); color: rgba(255,255,255,0.5);">Previous Member</td><td style="border-color: rgba(255,255,255,0.05);"><?= $profile->previous_member ? 'Yes' : 'No' ?></td></tr>
            </table>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- Notification Preferences -->
<?php if ($profile): ?>
<div class="glass-card mb-4">
    <h5 class="font-weight-bold mb-3"><i class="fas fa-bell mr-2" style="color: #f6c23e;"></i>Notification Preferences</h5>
    <div class="row">
        <div class="col-md-3 mb-2">
            <span class="glass-badge" style="background: <?= $profile->notify_conferences ? 'rgba(28,200,138,0.2)' : 'rgba(255,255,255,0.05)' ?>; color: <?= $profile->notify_conferences ? '#1cc88a' : 'rgba(255,255,255,0.4)' ?>;">
                <i class="fas fa-<?= $profile->notify_conferences ? 'check-circle' : 'times-circle' ?> mr-1"></i>Conferences
            </span>
        </div>
        <div class="col-md-3 mb-2">
            <span class="glass-badge" style="background: <?= $profile->notify_workshops ? 'rgba(28,200,138,0.2)' : 'rgba(255,255,255,0.05)' ?>; color: <?= $profile->notify_workshops ? '#1cc88a' : 'rgba(255,255,255,0.4)' ?>;">
                <i class="fas fa-<?= $profile->notify_workshops ? 'check-circle' : 'times-circle' ?> mr-1"></i>Workshops
            </span>
        </div>
        <div class="col-md-3 mb-2">
            <span class="glass-badge" style="background: <?= $profile->notify_webinars ? 'rgba(28,200,138,0.2)' : 'rgba(255,255,255,0.05)' ?>; color: <?= $profile->notify_webinars ? '#1cc88a' : 'rgba(255,255,255,0.4)' ?>;">
                <i class="fas fa-<?= $profile->notify_webinars ? 'check-circle' : 'times-circle' ?> mr-1"></i>Webinars
            </span>
        </div>
        <div class="col-md-3 mb-2">
            <span class="glass-badge" style="background: <?= $profile->notify_research ? 'rgba(28,200,138,0.2)' : 'rgba(255,255,255,0.05)' ?>; color: <?= $profile->notify_research ? '#1cc88a' : 'rgba(255,255,255,0.4)' ?>;">
                <i class="fas fa-<?= $profile->notify_research ? 'check-circle' : 'times-circle' ?> mr-1"></i>Research
            </span>
        </div>
        <div class="col-md-3 mb-2">
            <span class="glass-badge" style="background: <?= $profile->notify_scholarships ? 'rgba(28,200,138,0.2)' : 'rgba(255,255,255,0.05)' ?>; color: <?= $profile->notify_scholarships ? '#1cc88a' : 'rgba(255,255,255,0.4)' ?>;">
                <i class="fas fa-<?= $profile->notify_scholarships ? 'check-circle' : 'times-circle' ?> mr-1"></i>Scholarships
            </span>
        </div>
        <div class="col-md-3 mb-2">
            <span class="glass-badge" style="background: <?= $profile->notify_news ? 'rgba(28,200,138,0.2)' : 'rgba(255,255,255,0.05)' ?>; color: <?= $profile->notify_news ? '#1cc88a' : 'rgba(255,255,255,0.4)' ?>;">
                <i class="fas fa-<?= $profile->notify_news ? 'check-circle' : 'times-circle' ?> mr-1"></i>News & Updates
            </span>
        </div>
    </div>
</div>
<?php endif; ?>

<!-- Audit Logs -->
<?php if ($auditLogs): ?>
<div class="glass-card mb-4">
    <h5 class="font-weight-bold mb-3"><i class="fas fa-history mr-2" style="color: #858796;"></i>Activity History</h5>
    <div class="glass-table">
        <table>
            <thead>
                <tr>
                    <th>Date</th>
                    <th>Action</th>
                    <th>Performed By</th>
                    <th>Description</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($auditLogs as $log): ?>
                <tr>
                    <td><?= date('M d, Y h:i A', strtotime($log->created_at)) ?></td>
                    <td><span class="glass-badge"><?= htmlspecialchars($log->action) ?></span></td>
                    <td><?= htmlspecialchars($log->user_name ?: 'System') ?></td>
                    <td style="color: rgba(255,255,255,0.6);"><?= htmlspecialchars($log->description) ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
    </div>
</div>
<?php endif; ?>

<!-- Action Buttons -->
<div class="glass-card mb-4">
    <div class="row align-items-center">
        <div class="col-lg-6 mb-3 mb-lg-0">
            <h5 class="font-weight-bold mb-1">Decision</h5>
            <p style="color: rgba(255,255,255,0.6); margin: 0;">Approve or reject this membership application. An email notification will be sent to the applicant.</p>
        </div>
        <div class="col-lg-6 text-lg-right">
            <form method="POST" action="<?= $baseUrl ?>/users/<?= $user->id ?>/approve" style="display:inline;" onsubmit="return confirm('Approve this membership? An approval email will be sent to <?= htmlspecialchars($user->email) ?>.');">
                <button type="submit" class="glass-btn glass-btn-success mr-2 mb-2"><i class="fas fa-check mr-1"></i>Approve Membership</button>
            </form>
            <button type="button" class="glass-btn glass-btn-danger mb-2" data-toggle="modal" data-target="#rejectModal"><i class="fas fa-times mr-1"></i>Reject Membership</button>
        </div>
    </div>
</div>

<!-- Reject Modal -->
<div class="modal fade" id="rejectModal" 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(trim($user->first_name . ' ' . $user->other_names . ' ' . $user->last_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>
