<?php $title = 'Member Reports'; ?>

<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-file-alt mr-2"></i>Member Reports</h1>
    <span style="color: rgba(255,255,255,0.5); font-size: 0.9rem;"><strong style="color: #fff;"><?= $pagination->total ?></strong> member(s)</span>
</div>

<div class="glass-card mb-4">
    <form method="GET" class="form-inline">
        <div class="input-group w-100">
            <input type="text" name="search" class="form-control glass-input" placeholder="Search by name, email, or phone..." value="<?= htmlspecialchars($search) ?>">
            <div class="input-group-append">
                <button class="glass-btn glass-btn-primary" type="submit"><i class="fas fa-search"></i> Search</button>
            </div>
        </div>
    </form>
</div>

<div class="glass-table">
    <table class="table">
        <thead>
            <tr>
                <th>Name</th>
                <th>Email</th>
                <th>Phone</th>
                <th>Category</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            <?php if (!empty($members)): ?>
                <?php foreach ($members as $member): ?>
                <tr>
                    <td><img src="<?= $baseUrl ?>/img/undraw_profile.svg" style="width: 32px; height: 32px; border-radius: 50%; margin-right: 8px; vertical-align: middle; background: rgba(255,255,255,0.1); padding: 2px;"><?= htmlspecialchars($member->first_name ? trim($member->first_name . ' ' . $member->last_name) : $member->name) ?></td>
                    <td><?= htmlspecialchars($member->email) ?></td>
                    <td><?= htmlspecialchars($member->mobile_phone ?? '-') ?></td>
                    <td><?= $member->membership_category ? '<span class="glass-badge">' . htmlspecialchars($member->membership_category) . '</span>' : '-' ?></td>
                    <td><a href="<?= $baseUrl ?>/reports/members/<?= $member->id ?>" class="glass-btn glass-btn-primary btn-sm"><i class="fas fa-file-alt mr-1"></i>View Report</a></td>
                </tr>
                <?php endforeach; ?>
            <?php else: ?>
                <tr><td colspan="5" class="text-center" style="color: rgba(255,255,255,0.5);">No members found</td></tr>
            <?php endif; ?>
        </tbody>
    </table>
</div>

<?php if ($pagination && $pagination->lastPage > 1): ?>
<div class="d-flex justify-content-center mt-4">
    <nav><ul class="pagination" style="gap: 4px;">
        <?php if ($pagination->page > 1): ?>
        <li class="page-item"><a class="glass-btn btn-sm" href="?<?= http_build_query(array_merge($_GET, ['page' => 1])) ?>"><i class="fas fa-angle-double-left"></i></a></li>
        <li class="page-item"><a class="glass-btn btn-sm" href="?<?= http_build_query(array_merge($_GET, ['page' => $pagination->page - 1])) ?>"><i class="fas fa-angle-left"></i></a></li>
        <?php endif; ?>
        <?php $start = max(1, $pagination->page - 2); $end = min($pagination->lastPage, $pagination->page + 2); for ($i = $start; $i <= $end; $i++): ?>
        <li class="page-item <?= $i == $pagination->page ? 'active' : '' ?>"><a class="glass-btn btn-sm" href="?<?= http_build_query(array_merge($_GET, ['page' => $i])) ?>"><?= $i ?></a></li>
        <?php endfor; ?>
        <?php if ($pagination->page < $pagination->lastPage): ?>
        <li class="page-item"><a class="glass-btn btn-sm" href="?<?= http_build_query(array_merge($_GET, ['page' => $pagination->page + 1])) ?>"><i class="fas fa-angle-right"></i></a></li>
        <li class="page-item"><a class="glass-btn btn-sm" href="?<?= http_build_query(array_merge($_GET, ['page' => $pagination->lastPage])) ?>"><i class="fas fa-angle-double-right"></i></a></li>
        <?php endif; ?>
    </ul></nav>
</div>
<?php endif; ?>
