<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-edit me-2" style="color: var(--nis-primary);"></i>
                    Edit Migrant: <?= htmlspecialchars($migrant['surname']) ?>, <?= htmlspecialchars($migrant['given_name']) ?>
                </h2>
                <a href="<?= APP_URL ?>/migrants/<?= $migrant['person_id'] ?>" class="btn btn-outline-secondary">
                    <i class="fas fa-arrow-left me-2"></i> Back to Profile
                </a>
            </div>
        </div>
    </div>
    
    <!-- Display current status warning if needed -->
    <?php if (isset($migrant['current_status']['status']) && $migrant['current_status']['status'] == 'Rejected'): ?>
        <div class="alert alert-warning">
            <i class="fas fa-exclamation-triangle me-2"></i>
            This application was rejected. Please make necessary changes and resubmit.
            <?php if (!empty($migrant['current_status']['remarks'])): ?>
                <br><strong>Rejection reason:</strong> <?= htmlspecialchars($migrant['current_status']['remarks']) ?>
            <?php endif; ?>
        </div>
    <?php endif; ?>
    
    <form method="POST" action="<?= APP_URL ?>/migrants/<?= $migrant['person_id'] ?>/update">
        <input type="hidden" name="csrf_token" value="<?= $csrf_token ?>">
        
        <!-- Biographical Information Section -->
        <div class="card mb-4">
            <div class="card-header">
                <i class="fas fa-id-card me-2"></i>
                BIOGRAPHICAL INFORMATION
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-4 mb-3">
                        <label class="form-label">DOCUMENT TYPE <span class="text-danger">*</span></label>
                        <select name="document_type" class="form-select" required>
                            <option value="">SELECT DOCUMENT TYPE</option>
                            <option value="PASSPORT" <?= ($migrant['document_type'] ?? '') == 'PASSPORT' ? 'selected' : '' ?>>PASSPORT</option>
                            <option value="REFUGEE PASSPORT" <?= ($migrant['document_type'] ?? '') == 'REFUGEE PASSPORT' ? 'selected' : '' ?>>REFUGEE PASSPORT</option>
                            <option value="EMERGENCY TRAVEL CERTIFICATE" <?= ($migrant['document_type'] ?? '') == 'EMERGENCY TRAVEL CERTIFICATE' ? 'selected' : '' ?>>EMERGENCY TRAVEL CERTIFICATE</option>
                            <option value="NATIONAL ID" <?= ($migrant['document_type'] ?? '') == 'NATIONAL ID' ? 'selected' : '' ?>>NATIONAL ID</option>
                            <option value="OTHER" <?= ($migrant['document_type'] ?? '') == 'OTHER' ? 'selected' : '' ?>>OTHER</option>
                        </select>
                    </div>
                    
                    <div class="col-md-4 mb-3">
                        <label class="form-label">COUNTRY OF ISSUE <span class="text-danger">*</span></label>
                        <input type="text" name="country_of_issue" class="form-control" 
                               value="<?= htmlspecialchars($migrant['country_of_issue'] ?? '') ?>" required>
                    </div>
                    
                    <div class="col-md-4 mb-3">
                        <label class="form-label">DOCUMENT NO <span class="text-danger">*</span></label>
                        <input type="text" name="document_no" class="form-control" 
                               value="<?= htmlspecialchars($migrant['document_no'] ?? '') ?>" required>
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-md-4 mb-3">
                        <label class="form-label">SURNAME <span class="text-danger">*</span></label>
                        <input type="text" name="surname" class="form-control text-uppercase" 
                               value="<?= htmlspecialchars($migrant['surname'] ?? '') ?>" required>
                    </div>
                    
                    <div class="col-md-4 mb-3">
                        <label class="form-label">GIVEN NAME <span class="text-danger">*</span></label>
                        <input type="text" name="given_name" class="form-control text-uppercase" 
                               value="<?= htmlspecialchars($migrant['given_name'] ?? '') ?>" required>
                    </div>
                    
                    <div class="col-md-4 mb-3">
                        <label class="form-label">NATIONALITY <span class="text-danger">*</span></label>
                        <input type="text" name="nationality" class="form-control" 
                               value="<?= htmlspecialchars($migrant['nationality'] ?? '') ?>" required>
                    </div>
                </div>
                
                <div class="row">
                    <div class="col-md-3 mb-3">
                        <label class="form-label">DATE OF BIRTH <span class="text-danger">*</span></label>
                        <input type="date" name="date_of_birth" class="form-control" 
                               value="<?= $migrant['date_of_birth'] ?? '' ?>" required>
                    </div>
                    
                    <div class="col-md-3 mb-3">
                        <label class="form-label">SEX <span class="text-danger">*</span></label>
                        <select name="sex" class="form-select" required>
                            <option value="">SELECT SEX</option>
                            <option value="Male" <?= ($migrant['sex'] ?? '') == 'Male' ? 'selected' : '' ?>>MALE</option>
                            <option value="Female" <?= ($migrant['sex'] ?? '') == 'Female' ? 'selected' : '' ?>>FEMALE</option>
                            <option value="Other" <?= ($migrant['sex'] ?? '') == 'Other' ? 'selected' : '' ?>>OTHER</option>
                        </select>
                    </div>
                    
                    <div class="col-md-3 mb-3">
                        <label class="form-label">EXPIRY DATE</label>
                        <input type="date" name="expiry_date" class="form-control" 
                               value="<?= $migrant['expiry_date'] ?? '' ?>">
                    </div>
                    
                    <div class="col-md-3 mb-3">
                        <label class="form-label">NATIONAL ID NO</label>
                        <input type="text" name="national_id_no" class="form-control" 
                               value="<?= htmlspecialchars($migrant['national_id_no'] ?? '') ?>">
                    </div>
                </div>
                
                <!-- Add more fields as needed from your create form -->
                
            </div>
            <div class="card-footer">
                <button type="submit" class="btn btn-nis">
                    <i class="fas fa-save me-2"></i> Update Migrant
                </button>
                <a href="<?= APP_URL ?>/migrants/<?= $migrant['person_id'] ?>" class="btn btn-outline-secondary">
                    <i class="fas fa-times me-2"></i> Cancel
                </a>
            </div>
        </div>
    </form>
</div>