<?php
$db = Database::getInstance();
$upcoming = $db->fetchAll(
    "SELECT event_code, title_en, start_datetime, current_attendees, max_attendees, status
     FROM club_events WHERE start_datetime >= NOW() AND status NOT IN ('cancelled','completed')
     ORDER BY start_datetime LIMIT 3"
);
?>
<div class="card h-100">
    <div class="card-header bg-transparent d-flex justify-content-between align-items-center">
        <h6 class="mb-0"><i class="fas fa-calendar-alt me-1 text-info"></i> <?= lang('facilities.upcoming_events') ?></h6>
        <a href="/events" class="small">View all</a>
    </div>
    <div class="card-body p-0">
        <?php if (empty($upcoming)): ?>
        <div class="text-center text-muted py-3">No upcoming events</div>
        <?php else: ?>
        <div class="list-group list-group-flush">
            <?php foreach ($upcoming as $ev): ?>
            <div class="list-group-item">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <strong><?= e($ev['title_en']) ?></strong><br>
                        <small class="text-muted"><i class="fas fa-clock me-1"></i><?= format_datetime($ev['start_datetime']) ?></small>
                    </div>
                    <span class="badge bg-info"><?= $ev['current_attendees'] ?><?= $ev['max_attendees'] ? '/' . $ev['max_attendees'] : '' ?></span>
                </div>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div>
</div>