<?php
$db = Database::getInstance();
$wlData = $db->fetchAll(
    "SELECT mt.name_en, wl.current_entries, wl.max_entries, wl.is_open
     FROM waiting_lists wl
     JOIN membership_types mt ON wl.membership_type_id = mt.id
     ORDER BY mt.sort_order LIMIT 5"
);
$totalWaiting = 0;
foreach ($wlData as $w) { $totalWaiting += (int)$w['current_entries']; }
?>
<div class="card border-info h-100">
    <div class="card-body">
        <div class="d-flex justify-content-between mb-2">
            <div>
                <h6 class="text-muted mb-1"><?= lang('applications.waiting_list') ?></h6>
                <h3 class="mb-0"><?= number_format($totalWaiting) ?></h3>
            </div>
            <div class="align-self-center"><i class="fas fa-hourglass-half fa-2x text-info opacity-50"></i></div>
        </div>
        <?php if (!empty($wlData)): ?>
        <div class="small">
            <?php foreach ($wlData as $w): ?>
            <div class="d-flex justify-content-between">
                <span><?= e($w['name_en']) ?></span>
                <span class="fw-bold"><?= $w['current_entries'] ?><?= $w['max_entries'] ? '/' . $w['max_entries'] : '' ?></span>
            </div>
            <?php endforeach; ?>
        </div>
        <?php endif; ?>
    </div>
    <div class="card-footer bg-transparent border-0 pt-0">
        <a href="/waiting-list" class="text-decoration-none small">View all →</a>
    </div>
</div>