<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <h2 class="mb-4">
                <i class="fas fa-search me-2" style="color: var(--nis-primary);"></i>
                Search Migrants
            </h2>
        </div>
    </div>
    
    <!-- Search Form - FIXED ACTION URL -->
    <div class="card mb-4">
        <div class="card-header">
            <i class="fas fa-filter"></i> Search Filters
        </div>
        <div class="card-body">
            <form method="GET" action="<?= APP_URL ?>/migrants/search">
                <div class="row">
                    <div class="col-md-3 mb-3">
                        <label class="form-label">Person ID</label>
                        <input type="text" name="person_id" class="form-control" value="<?= htmlspecialchars($searchParams['person_id'] ?? '') ?>">
                    </div>
                    
                    <div class="col-md-3 mb-3">
                        <label class="form-label">Surname</label>
                        <input type="text" name="surname" class="form-control" value="<?= htmlspecialchars($searchParams['surname'] ?? '') ?>">
                    </div>
                    
                    <div class="col-md-3 mb-3">
                        <label class="form-label">Document No</label>
                        <input type="text" name="document_no" class="form-control" value="<?= htmlspecialchars($searchParams['document_no'] ?? '') ?>">
                    </div>
                    
                    <div class="col-md-3 mb-3">
                        <label class="form-label">Nationality</label>
                        <input type="text" name="nationality" class="form-control" value="<?= htmlspecialchars($searchParams['nationality'] ?? '') ?>">
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-md-3 mb-3">
                        <label class="form-label">Email</label>
                        <input type="email" name="email" class="form-control" value="<?= htmlspecialchars($searchParams['email'] ?? '') ?>">
                    </div>
                    
                    <div class="col-md-3 mb-3">
                        <label class="form-label">Status</label>
                        <select name="status" class="form-select">
                            <option value="">All Status</option>
                            <option value="Draft" <?= ($searchParams['status'] ?? '') == 'Draft' ? 'selected' : '' ?>>Draft</option>
                            <option value="Submitted" <?= ($searchParams['status'] ?? '') == 'Submitted' ? 'selected' : '' ?>>Submitted</option>
                            <option value="Under Review" <?= ($searchParams['status'] ?? '') == 'Under Review' ? 'selected' : '' ?>>Under Review</option>
                            <option value="Approved" <?= ($searchParams['status'] ?? '') == 'Approved' ? 'selected' : '' ?>>Approved</option>
                            <option value="Rejected" <?= ($searchParams['status'] ?? '') == 'Rejected' ? 'selected' : '' ?>>Rejected</option>
                        </select>
                    </div>
                    
                    <div class="col-md-6 mb-3 d-flex align-items-end">
                        <button type="submit" class="btn btn-nis me-2">
                            <i class="fas fa-search"></i> Search
                        </button>
                        <a href="<?= APP_URL ?>/migrants/search" class="btn btn-outline-secondary">
                            <i class="fas fa-undo"></i> Reset
                        </a>
                    </div>
                </div>
            </form>
        </div>
    </div>
    
    <!-- Search Results -->
    <div class="card">
        <div class="card-header">
            <i class="fas fa-list"></i> Search Results (<?= count($results) ?> found)
        </div>
        <div class="card-body">
            <?php if (empty($results)): ?>
                <div class="text-center py-5">
                    <i class="fas fa-search fa-3x text-muted mb-3"></i>
                    <p class="text-muted">No results found. Try different search criteria.</p>
                </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>Date of Birth</th>
                                <th>Created</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php foreach ($results as $migrant): ?>
                            <tr>
                                <td><code><?= htmlspecialchars($migrant['person_id']) ?></code></td>
                                <td><?= htmlspecialchars($migrant['surname']) ?>, <?= htmlspecialchars($migrant['given_name']) ?></td>
                                <td><?= htmlspecialchars($migrant['document_no']) ?></td>
                                <td><?= htmlspecialchars($migrant['nationality']) ?></td>
                                <td><?= date('d/m/Y', strtotime($migrant['date_of_birth'])) ?></td>
                                <td><?= date('d/m/Y', strtotime($migrant['created_at'])) ?></td>
                                <td>
                                    <a href="<?= APP_URL ?>/migrants/<?= urlencode($migrant['person_id']) ?>" 
                                       class="btn btn-sm btn-outline-nis">
                                        <i class="fas fa-eye"></i> View
                                    </a>
                                </td>
                            </tr>
                            <?php endforeach; ?>
                        </tbody>
                    </table>
                </div>
            <?php endif; ?>
        </div>
    </div>
</div>