<div class="container-fluid">
    <div class="row justify-content-center">
        <div class="col-md-11">
            <div class="card border-0 shadow-sm" style="border-radius: 15px;">
                <div class="card-header bg-white border-0 pt-4 px-4">
                    <h5 class="mb-0">Edit Data Warga</h5>
                </div>
                <div class="card-body px-4 pb-4">
                    <?php echo validation_errors('<div class="alert alert-danger">', '</div>'); ?>
                    
                    <form action="<?php echo base_url('warga/edit/'.$warga->id); ?>" method="post">
                        
                        <!-- Section: Data KK -->
                        <div class="bg-light p-3 rounded mb-4">
                            <h6 class="text-primary mb-3"><i class="bi bi-house-door"></i> Data Kartu Keluarga</h6>
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Nomor KK</label>
                                    <input type="text" name="no_kk" class="form-control" value="<?php echo $warga->no_kk; ?>" maxlength="16">
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Status Hubungan dalam KK</label>
                                    <select name="status_hubungan" class="form-select">
                                        <?php foreach($status_hubungan as $key => $value): ?>
                                        <option value="<?php echo $key; ?>" <?php echo ($warga->status_hubungan == $key) ? 'selected' : ''; ?>>
                                            <?php echo $value; ?>
                                        </option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                        </div>

                        <!-- Section: Data Pribadi -->
                        <div class="bg-light p-3 rounded mb-4">
                            <h6 class="text-primary mb-3"><i class="bi bi-person"></i> Data Pribadi</h6>
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">NIK</label>
                                    <input type="text" class="form-control" value="<?php echo $warga->nik; ?>" readonly disabled>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Nama Lengkap <span class="text-danger">*</span></label>
                                    <input type="text" name="nama_lengkap" class="form-control" value="<?php echo $warga->nama_lengkap; ?>" required>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Jenis Kelamin</label>
                                    <select name="jenis_kelamin" class="form-select">
                                        <option value="L" <?php echo ($warga->jenis_kelamin == 'L') ? 'selected' : ''; ?>>Laki-laki</option>
                                        <option value="P" <?php echo ($warga->jenis_kelamin == 'P') ? 'selected' : ''; ?>>Perempuan</option>
                                    </select>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Agama</label>
                                    <select name="agama" class="form-select">
                                        <option value="">-- Pilih --</option>
                                        <option value="Islam" <?php echo ($warga->agama == 'Islam') ? 'selected' : ''; ?>>Islam</option>
                                        <option value="Kristen" <?php echo ($warga->agama == 'Kristen') ? 'selected' : ''; ?>>Kristen</option>
                                        <option value="Katolik" <?php echo ($warga->agama == 'Katolik') ? 'selected' : ''; ?>>Katolik</option>
                                        <option value="Hindu" <?php echo ($warga->agama == 'Hindu') ? 'selected' : ''; ?>>Hindu</option>
                                        <option value="Buddha" <?php echo ($warga->agama == 'Buddha') ? 'selected' : ''; ?>>Buddha</option>
                                        <option value="Konghucu" <?php echo ($warga->agama == 'Konghucu') ? 'selected' : ''; ?>>Konghucu</option>
                                    </select>
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Tempat Lahir</label>
                                    <input type="text" name="tempat_lahir" class="form-control" value="<?php echo $warga->tempat_lahir; ?>">
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Tanggal Lahir</label>
                                    <input type="date" name="tanggal_lahir" class="form-control" value="<?php echo $warga->tanggal_lahir; ?>">
                                </div>
                            </div>

                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Status Perkawinan</label>
                                    <select name="status_perkawinan" class="form-select">
                                        <option value="belum_kawin" <?php echo ($warga->status_perkawinan == 'belum_kawin') ? 'selected' : ''; ?>>Belum Kawin</option>
                                        <option value="kawin" <?php echo ($warga->status_perkawinan == 'kawin') ? 'selected' : ''; ?>>Kawin</option>
                                        <option value="cerai_hidup" <?php echo ($warga->status_perkawinan == 'cerai_hidup') ? 'selected' : ''; ?>>Cerai Hidup</option>
                                        <option value="cerai_mati" <?php echo ($warga->status_perkawinan == 'cerai_mati') ? 'selected' : ''; ?>>Cerai Mati</option>
                                    </select>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Pekerjaan</label>
                                    <input type="text" name="pekerjaan" class="form-control" value="<?php echo $warga->pekerjaan; ?>">
                                </div>
                            </div>
                        </div>

                        <!-- Section: Domisili -->
                        <div class="bg-light p-3 rounded mb-4">
                            <h6 class="text-primary mb-3"><i class="bi bi-geo-alt"></i> Status Domisili</h6>
                            <div class="row">
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Status Domisili</label>
                                    <select name="status_domisili" class="form-select">
                                        <?php foreach($status_domisili as $key => $value): ?>
                                        <option value="<?php echo $key; ?>" <?php echo ($warga->status_domisili == $key) ? 'selected' : ''; ?>>
                                            <?php echo $value; ?>
                                        </option>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                                <div class="col-md-6 mb-3">
                                    <label class="form-label">Keterangan Domisili</label>
                                    <input type="text" name="keterangan_domisili" class="form-control" value="<?php echo $warga->keterangan_domisili; ?>">
                                </div>
                            </div>
                            
                            <div class="mb-3">
                                <label class="form-label">Alamat Lengkap</label>
                                <textarea name="alamat" class="form-control" rows="3"><?php echo isset($warga->alamat) ? $warga->alamat : ''; ?></textarea>
                            </div>
                        </div>

                        <div class="d-flex justify-content-between">
                            <a href="<?php echo base_url('warga'); ?>" class="btn btn-secondary">Kembali</a>
                            <button type="submit" class="btn btn-primary">Update Data</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>