<!-- Tambah Anggoia Baru -->
<div class="modal fade" id="tambahAnggota" tabindex="-1" role="dialog" aria-labelledby="tambahAnggotaTitle"
    aria-hidden="true">
    <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="tambahAnggotaTitle">
                    Tambah Anggota Arisan
                </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <?php echo form_open_multipart('arisan/data/kelompok_motor/crud'); ?>
                <input type="hidden" name="<?= $this->security->get_csrf_token_name(); ?>"
                    value="<?= $this->security->get_csrf_hash(); ?>" style="display: none">
                <div class="form-group">
                    <label>Nomor Induk Kependudukan ( NIK )</label>
                    <input type="number" class="form-control" onkeyup="nik_anggota_tambah()" id="nik_tambah"
                        name="nik_tambah" placeholder="Nomor Induk Kependudukan ( NIK )" required>
                    <input type="text" class="form-control" hidden id="regist_arisan" name="regist_arisan"
                        value="<?= $identitas_arisan['id'] ?>" placeholder="Nomor Induk Kependudukan ( NIK )" required>
                    <input type="text" class="form-control" hidden id="login_id" name="login_id"
                        value="<?= $data_id_login ?>" placeholder="Nomor Induk Kependudukan ( NIK )" required>
                </div>
                <div class="form-group">
                    <label>Nama Panggilan</label>
                    <input type="text" class="form-control" id="nm_anggota" name="nm_anggota"
                        placeholder="Nama Anggota Kelompok Arisan" required>
                    <input type="text" class="form-control" hidden id="anggota_terdaftar" name="anggota_terdaftar"
                        placeholder="Nama Anggota Kelompok Arisan" required>
                </div>
                <div class="form-group">
                    <label>Jenis Kelamin</label>
                    <select class="form-control" id="jk" name="jk" required>
                        <option value="1">LAKI-LAKI</option>
                        <option value="2">PEREMPUAN</option>
                    </select>
                </div>
                <div class="form-group">
                    <label>Alamat Lengkap</label>
                    <textarea class="form-control" name="alamat_lengkap" id="alamat_lengkap" cols="30" rows="2"
                        placeholder="Mis. Jalan, Sekolah, Perumahan, Dst" required></textarea>
                </div>
                <div class="form-group">
                    <label for="">Pilih Kabupaten / Kota</label>
                    <select class="form-control" id="tambah_kota_kabupaten" name="tambah_kota_kabupaten" required>
                        <option value="PILIH">Pilih Kabupaten / Kota</option>
                        <?php foreach ($data_kota as $Data_kota) : ?>
                            <option value="<?= $Data_kota->kot_kab ?>"><?= $Data_kota->kot_kab ?></option>
                        <?php endforeach; ?>
                    </select>
                </div>
                <div class="form-row mb-4">
                    <div class="col-6">
                        <label for="">Pilih Kecamatan</label>
                        <select class="form-control" id="tambah_kecamatan_baru" name="tambah_kecamatan_baru" required>
                        </select>
                    </div>
                    <div class="col-6">
                        <label for="">Pilih Desa</label>
                        <select class="form-control" id="tambah_dk_ds" name="tambah_dk_ds" required>
                        </select>
                    </div>
                </div>
                <div class="form-row mb-4">
                    <div class="col">
                        <label for="">RT</label>
                        <select class="form-control" id="tambah_nm_rt" name="tambah_nm_rt" required>
                            <option value="001">001</option>
                            <option value="002">002</option>
                            <option value="003">003</option>
                            <option value="004">004</option>
                            <option value="005">005</option>
                            <option value="006">006</option>
                            <option value="007">007</option>
                            <option value="008">008</option>
                            <option value="009">009</option>
                            <option value="010">010</option>
                            <option value="011">011</option>
                            <option value="012">012</option>
                            <option value="013">013</option>
                            <option value="014">014</option>
                            <option value="015">015</option>
                            <option value="016">016</option>
                            <option value="017">017</option>
                            <option value="018">018</option>
                            <option value="019">019</option>
                            <option value="020">020</option>
                        </select>
                    </div>
                    <div class="col">
                        <label for="">RW</label>
                        <select class="form-control" id="tambah_nm_rw" name="tambah_nm_rw" required>
                            <option value="001">001</option>
                            <option value="002">002</option>
                            <option value="003">003</option>
                            <option value="004">004</option>
                            <option value="005">005</option>
                            <option value="006">006</option>
                            <option value="007">007</option>
                            <option value="008">008</option>
                            <option value="009">009</option>
                            <option value="010">010</option>
                            <option value="011">011</option>
                            <option value="012">012</option>
                            <option value="013">013</option>
                            <option value="014">014</option>
                            <option value="015">015</option>
                            <option value="016">016</option>
                            <option value="017">017</option>
                            <option value="018">018</option>
                            <option value="019">019</option>
                            <option value="020">020</option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label>Tempat Tanggal Lahir</label>
                    <div class="form-row mb-4">
                        <div class="col">
                            <input type="text" class="form-control" id="tempat_lahir" name="tempat_lahir"
                                placeholder="Tempat Lahir" required>
                        </div>
                        <div class="col">
                            <input type="date" max='<?= date("Y-m-d", strtotime("-18 year")); ?>' class="form-control"
                                id="tgl_lahir" name="tgl_lahir" placeholder="Tanggal Lahir" required>
                        </div>
                    </div>
                </div>
                <div class="form-group">
                    <label>Nomor HP</label>
                    <input type="number" class="form-control" id="no_hp" name="no_hp" placeholder="Nomor HP" required>
                </div>
                <div class="form-group">
                    <label>Pekerjaan</label>
                    <input type="text" class="form-control" id="pekerjaan" name="pekerjaan"
                        placeholder="Potongan Admin Setiap Bulan" required>
                </div>
                <div class="form-group">
                    <label>Suami / Istri</label>
                    <input type="text" class="form-control" id="suami_istri" name="suami_istri"
                        placeholder="Nama Suami atau Istri" required>
                    <small>*Jika belum menikah isi Belum Menikah, Duda, Janda</small>
                </div>
                <div class="form-group">
                    <label>Foto KTP</label>
                    <input type="file" class="form-control" id="foto_ktp" name="foto_ktp" placeholder="Foto KTP"
                        required>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-outline-primary" data-dismiss="modal">
                    Close
                </button>
                <button type="submit" id="simpanAnggotaArisanMotor" name="simpanAnggotaArisanMotor"
                    class="btn btn-primary">Simpan</button>
            </div>
            <?php echo form_close(); ?>
        </div>
    </div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
    function nik_anggota_tambah() {
        var nik = $("#nik_tambah").val();
        $.ajax({
            type: "POST",
            url: '<?= base_url('arisan/data/cek_anggota') ?>',
            data: 'nik=' + nik,
            success: function(data) {
                var json = data,
                    obj = JSON.parse(json);
                if (obj > 1) {
                    $('#nm_anggota').val();
                    $('#jk').val();
                    $('#alamat_lengkap').val();
                    $('#kode_pos').val();
                    $('#nm_rt').val();
                    $('#nm_rw').val();
                    $('#nm_desa').val();
                    $('#nm_kecamatan').val();
                    $('#kot_kab').val();
                    $('#prov').val();
                    $('#tempat_lahir').val();
                    $('#tgl_lahir').val();
                    $('#tam_alamat_id').val();
                    $('#no_hp').val();
                    $('#pekerjaan').val();
                    $('#suami_istri').val();
                    $('#anggota_terdaftar').val();
                } else {
                    $('#nm_anggota').val(obj.nm_anggota);
                    $('#jk').val(obj.jk);
                    $('#alamat_lengkap').val(obj.alamat_lengkap);
                    $('#kode_pos').val(obj.kd_pos);
                    $('#nm_rt').val(obj.nm_rt);
                    $('#nm_rw').val(obj.nm_rw);
                    $('#tambah_kota_kabupaten').html(obj.kota_kabupaten);
                    $('#tambah_kecamatan_baru').html(obj.kecamatan_baru);
                    $('#tambah_dk_ds').html(obj.dk_ds);
                    $('#tempat_lahir').val(obj.tempat_lahir);
                    $('#tgl_lahir').val(obj.tgl_lahir);
                    $('#tam_alamat_id').val(obj.id_alamat);
                    $('#no_hp').val(obj.no_hp);
                    $('#pekerjaan').val(obj.pekerjaan);
                    $('#suami_istri').val(obj.suami_istri);
                    $('#anggota_terdaftar').val(obj.jk);
                }
            }
        })
    }
</script>
<!-- Script_alamat Baru -->
<script type="text/javascript">
    $('#tambah_kota_kabupaten').change(function() {
        var nm_kot_kab = $(this).val();
        $.ajax({
            type: 'POST',
            url: '<?= base_url('arisan/kot_kab') ?>',
            data: 'nm_kot_kab=' + nm_kot_kab,
            success: function(response) {
                $('#tambah_kecamatan_baru').html(response);
            }
        });
    });

    $('#tambah_kecamatan_baru').change(function() {
        var nm_kecamatan = $(this).val();
        $.ajax({
            type: 'POST',
            url: '<?= base_url('arisan/kecamatan') ?>',
            data: 'nm_kecamatan=' + nm_kecamatan,
            success: function(response) {
                $('#tambah_dk_ds').html(response);
            }
        });
    });
</script>