<?php
$db = Database::getInstance();
$pending = $db->fetchOne(
    "SELECT
        SUM(CASE WHEN status = 'submitted' THEN 1 ELSE 0 END) as submitted,
        SUM(CASE WHEN status = 'under_review' THEN 1 ELSE 0 END) as under_review,
        SUM(CASE WHEN status = 'board_pending' THEN 1 ELSE 0 END) as board_pending,
        SUM(CASE WHEN status NOT IN ('approved','rejected','cancelled','expired') THEN 1 ELSE 0 END) as total_pending
     FROM applications WHERE is_deleted = 0"
);
$totalPending = (int)($pending['total_pending'] ?? 0);
?>
<div class="card border-warning h-100">
    <div class="card-body">
        <div class="d-flex justify-content-between">
            <div>
                <h6 class="text-muted mb-1"><?= lang('applications.pending_applications') ?></h6>
                <h3 class="mb-0"><?= number_format($totalPending) ?></h3>
                <small class="text-muted">
                    Submitted: <?= (int)($pending['submitted'] ?? 0) ?> |
                    Review: <?= (int)($pending['under_review'] ?? 0) ?> |
                    Board: <?= (int)($pending['board_pending'] ?? 0) ?>
                </small>
            </div>
            <div class="align-self-center"><i class="fas fa-file-alt fa-2x text-warning opacity-50"></i></div>
        </div>
    </div>
    <div class="card-footer bg-transparent border-0 pt-0">
        <a href="/applications" class="text-decoration-none small">View all →</a>
    </div>
</div>