<div class="row mb-3">
    <div class="col-md-6">
        <label class="form-label">Nama Penuh</label>
        <input type="text" name="nama" class="form-control" 
               value="<?= isset($pelajar) ? htmlspecialchars($pelajar['nama']) : '' ?>" required>
    </div>
    <div class="col-md-3">
        <label class="form-label">No. IC</label>
        <input type="text" name="no_ic" class="form-control" 
               value="<?= isset($pelajar) ? htmlspecialchars($pelajar['no_ic']) : '' ?>" required>
    </div>
    <div class="col-md-3">
        <label class="form-label">No. Pendaftaran</label>
        <input type="text" name="no_pendaftaran" class="form-control" 
               value="<?= isset($pelajar) ? htmlspecialchars($pelajar['no_pendaftaran']) : '' ?>" required>
    </div>
</div>

<div class="row mb-3">
    <div class="col-md-4">
        <label class="form-label">Jantina</label>
        <select name="jantina" class="form-control" required>
            <option value="">-- Pilih Jantina --</option>
            <option value="Lelaki" <?= isset($pelajar) && $pelajar['jantina']=='Lelaki' ? 'selected' : '' ?>>Lelaki</option>
            <option value="Perempuan" <?= isset($pelajar) && $pelajar['jantina']=='Perempuan' ? 'selected' : '' ?>>Perempuan</option>
        </select>
    </div>
    <div class="col-md-4">
        <label class="form-label">Bangsa</label>
        <select name="bangsa" class="form-control" required>
            <?php
            $bangsa_list = ['Melayu','Cina','India','Orang Asli','Bumiputera Sabah','Bumiputera Sarawak','Lain-lain'];
            foreach ($bangsa_list as $b) {
                $sel = isset($pelajar) && $pelajar['bangsa']==$b ? 'selected' : '';
                echo "<option value='$b' $sel>$b</option>";
            }
            ?>
        </select>
    </div>
    <div class="col-md-4">
        <label class="form-label">Agama</label>
        <select name="agama" class="form-control" required>
            <?php
            $agama_list = ['Islam','Kristian','Hindu','Buddha','Lain-lain'];
            foreach ($agama_list as $a) {
                $sel = isset($pelajar) && $pelajar['agama']==$a ? 'selected' : '';
                echo "<option value='$a' $sel>$a</option>";
            }
            ?>
        </select>
    </div>
</div>

<div class="row mb-3">
    <div class="col-md-4">
        <label class="form-label">Warganegara</label>
        <select name="warganegara" class="form-control" required>
            <?php
            $warga_list = ['Malaysia','Bukan Warganegara','Lain-lain'];
            foreach ($warga_list as $w) {
                $sel = isset($pelajar) && $pelajar['warganegara']==$w ? 'selected' : '';
                echo "<option value='$w' $sel>$w</option>";
            }
            ?>
        </select>
    </div>
    <div class="col-md-4">
        <label class="form-label">Program</label>
        <select name="program" class="form-control" required>
            <?php
            $program_list = ['SIJIL TEKNOLOGI MAKLUMAT','SIJIL TEKNOLOGI ELEKTRIK','DIPLOMA TEKNOLOGI ELEKTRONIK INSTRUMENTASI'];
            foreach ($program_list as $p) {
                $sel = isset($pelajar) && $pelajar['program']==$p ? 'selected' : '';
                echo "<option value='$p' $sel>$p</option>";
            }
            ?>
        </select>
    </div>
    <div class="col-md-4">
        <label class="form-label">Emel</label>
        <input type="email" name="emel" class="form-control" 
               value="<?= isset($pelajar) ? htmlspecialchars($pelajar['emel']) : '' ?>" required>
    </div>
</div>

<div class="row mb-3">
    <div class="col-md-4">
        <label class="form-label">No. Telefon</label>
        <input type="text" name="no_telefon" class="form-control" 
               value="<?= isset($pelajar) ? htmlspecialchars($pelajar['no_telefon']) : '' ?>">
    </div>
    <div class="col-md-4">
        <label class="form-label">Username</label>
        <input type="text" name="username" class="form-control" 
               value="<?= isset($pelajar) ? htmlspecialchars($pelajar['username']) : '' ?>" required>
    </div>
    <div class="col-md-4">
        <label class="form-label">Kata Laluan <?= isset($pelajar) ? '(Kosongkan jika tidak tukar)' : '' ?></label>
        <input type="password" name="kata_laluan" class="form-control">
    </div>
</div>

<div class="mb-3">
    <label class="form-label">Gambar Pelajar</label><br>
    <?php if (isset($pelajar) && $pelajar['gambar']): ?>
        <img src="uploads/pelajar/<?= $pelajar['gambar'] ?>" width="100" class="mb-2"><br>
    <?php endif; ?>
    <input type="file" name="gambar" class="form-control" accept="image/*">
</div>

<div class="mb-3">
    <label class="form-label">Status</label>
    <select name="status" class="form-control" required>
        <option value="Aktif" <?= isset($pelajar) && $pelajar['status']=='Aktif' ? 'selected' : '' ?>>Aktif</option>
        <option value="Tidak Aktif" <?= isset($pelajar) && $pelajar['status']=='Tidak Aktif' ? 'selected' : '' ?>>Tidak Aktif</option>
    </select>
</div>
