<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2>
                    <i class="fas fa-times-circle me-2" style="color: var(--nis-primary);"></i>
                    Rejected Applications
                </h2>
                <div>
                    <a href="<?= APP_URL ?>/migrants/search" class="btn btn-outline-secondary me-2">
                        <i class="fas fa-search"></i> Search
                    </a>
                    <a href="<?= APP_URL ?>/pending" class="btn btn-outline-warning">
                        <i class="fas fa-clock"></i> Pending
                    </a>
                </div>
            </div>
        </div>
    </div>
    
    <div class="card">
        <div class="card-header bg-white">
            <div class="d-flex align-items-center">
                <div class="rounded-circle bg-danger p-2 me-2">
                    <i class="fas fa-times text-white"></i>
                </div>
                <h5 class="mb-0">Rejected Applications</h5>
                <span class="badge bg-danger ms-2"><?= count($applications) ?> Total</span>
            </div>
        </div>
        <div class="card-body">
            <?php if (empty($applications)): ?>
                <div class="text-center py-5">
                    <i class="fas fa-times-circle fa-4x text-danger mb-3 opacity-50"></i>
                    <h5>No Rejected Applications</h5>
                    <p class="text-muted">There are no rejected applications to display.</p>
                    <a href="<?= APP_URL ?>/pending" class="btn btn-nis mt-2">
                        <i class="fas fa-clock me-2"></i> View Pending Applications
                    </a>
                </div>
            <?php else: ?>
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>Person ID</th>
                                <th>Name</th>
                                <th>Document No</th>
                                <th>Nationality</th>
                                <th>Rejected Date</th>
                                <th>Rejection Reason</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($applications as $app): ?>
                            <tr>
                                <td><code><?= htmlspecialchars($app['person_id']) ?></code></td>
                                <td>
                                    <strong><?= htmlspecialchars($app['surname']) ?></strong>, <?= htmlspecialchars($app['given_name']) ?>
                                </td>
                                <td><?= htmlspecialchars($app['document_no']) ?></td>
                                <td><?= htmlspecialchars($app['nationality']) ?></td>
                                <td>
                                    <i class="fas fa-calendar-alt text-danger me-1"></i>
                                    <?= date('d/m/Y H:i', strtotime($app['updated_at'] ?? $app['created_at'])) ?>
                                </td>
                                <td>
                                    <?php if (!empty($app['remarks'])): ?>
                                        <div class="alert alert-danger py-1 px-2 mb-0" style="font-size: 0.9rem;">
                                            <i class="fas fa-exclamation-triangle me-1"></i>
                                            <?= htmlspecialchars($app['remarks']) ?>
                                        </div>
                                    <?php else: ?>
                                        <span class="text-muted">No reason provided</span>
                                    <?php endif; ?>
                                </td>
                                <td>
                                    <a href="<?= APP_URL ?>/migrants/<?= urlencode($app['person_id']) ?>" 
                                       class="btn btn-sm btn-outline-danger">
                                        <i class="fas fa-eye"></i> View
                                    </a>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>