<?php
$db = Database::getInstance();
$active = (int) $db->fetchColumn("SELECT COUNT(*) FROM member_freezes WHERE status = 'active'");
$pending = (int) $db->fetchColumn("SELECT COUNT(*) FROM member_freezes WHERE status = 'pending'");
$recentFreezes = $db->fetchAll(
    "SELECT mf.freeze_number, mf.status, m.full_name_en, DATEDIFF(COALESCE(mf.actual_end_date, mf.original_end_date), CURDATE()) AS days_left
     FROM member_freezes mf JOIN members m ON mf.member_id = m.id
     WHERE mf.status IN ('active','pending')
     ORDER BY mf.created_at DESC LIMIT 5"
);
?>
<div class="card h-100">
    <div class="card-header d-flex justify-content-between align-items-center">
        <h6 class="mb-0"><i class="fas fa-snowflake text-info me-2"></i>Freezes</h6>
        <div>
            <span class="badge bg-primary"><?= $active ?> active</span>
            <?php if ($pending): ?><span class="badge bg-warning text-dark"><?= $pending ?> pending</span><?php endif; ?>
        </div>
    </div>
    <div class="card-body p-0">
        <?php if (empty($recentFreezes)): ?>
        <div class="text-center text-muted py-4"><i class="fas fa-check-circle fa-2x mb-2"></i><br>No active freezes</div>
        <?php else: ?>
        <ul class="list-group list-group-flush">
            <?php foreach ($recentFreezes as $f): ?>
            <li class="list-group-item d-flex justify-content-between align-items-center py-2">
                <div><small class="fw-bold"><?= e($f['freeze_number']) ?></small><br><small><?= e($f['full_name_en']) ?></small></div>
                <?= status_badge($f['status']) ?>
            </li>
            <?php endforeach; ?>
        </ul>
        <?php endif; ?>
    </div>
    <div class="card-footer text-center"><a href="/freezes" class="small">View All →</a></div>
</div>