<?php
$db = Database::getInstance();
$count = (int) $db->fetchColumn("SELECT COUNT(*) FROM members WHERE status = 'active' AND is_deleted = 0");
$lastMonth = (int) $db->fetchColumn("SELECT COUNT(*) FROM members WHERE status = 'active' AND is_deleted = 0 AND activation_date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH)");
$trend = $lastMonth > 0 ? round((($count - $lastMonth) / $lastMonth) * 100, 1) : 0;
?>
<div class="card border-success h-100">
    <div class="card-body">
        <div class="d-flex justify-content-between">
            <div>
                <h6 class="text-muted mb-1"><?= lang('members.total_active') ?></h6>
                <h3 class="mb-0"><?= number_format($count) ?></h3>
                <?php if ($trend != 0): ?>
                <small class="<?= $trend > 0 ? 'text-success' : 'text-danger' ?>"><?= $trend > 0 ? '+' : '' ?><?= $trend ?>%</small>
                <?php endif; ?>
            </div>
            <div class="align-self-center"><i class="fas fa-users fa-2x text-success opacity-50"></i></div>
        </div>
    </div>
</div>