<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <div class="content-header">
    <div class="container-fluid">
      <?= $this->session->flashdata('msg') ?>
      <div class="row mb-2">
        <div class="col-sm-6">
          <h1 class="m-0">Balita</h1>
        </div><!-- /.col -->
        <div class="col-sm-6">
          <ol class="breadcrumb float-sm-right">
            <li class="breadcrumb-item"><a href="<?=base_url('dashboard')?>">Beranda</a></li>
            <li class="breadcrumb-item active">Balita</li>
          </ol>
        </div><!-- /.col -->
      </div><!-- /.row -->
    </div><!-- /.container-fluid -->
  </div>
  <!-- /.content-header -->

  <!-- Main content -->
  <div class="content">
    <div class="container-fluid">
      <div class="card">
        <!-- /.card-header -->
        <div class="card-body">
          <a data-toggle="modal" data-target="#tambah" href=""><button class="btn btn-sm bg-blue text-white">Tambah
              Data Balita</button></a>
          <br><br>
          <div class="table-responsive">
            <table class="table table-flush" id="datatable-basic">
              <thead>
                <tr>
                  <th>#No</th>
                  <th>Nama </th>
                  <th>Jenis Kelamin </th>
                  <th>Umur</th>
                  <th>Nama Orang Tua</th>
                  <th>Aksi</th>
                </tr>
              </thead>
              <tbody>
                <?php $i = 1; foreach ($list_balita as $row): ?>
                <tr>
                  <td><?= $i++ ?> </td>
                  <td><?= $row->nama_balita ?></td>
                  <td><?= $row->jk ?></td>
                  <td><?= $row->umur ?> Bulan</td>
                  <td><?= $row->nama_ortu ?></td>
                  <td>
                    <a href="<?= base_url('balita/detailbalita/'.$row->id_balita)?>"><button
                        class="btn btn-sm bg-info text-white">Detail</button></a>
                    <a href="<?= base_url('balita/perhitungan/'.$row->id_balita)?>"><button
                        class="btn btn-sm bg-success text-white">Proses
                        Hitung SAW</button></a>
                    <a data-toggle="modal" data-target="#edit-<?=$row->id_balita?>" href=""><button
                        class="btn btn-sm bg-warning text-white">Edit</button></a>
                    <a data-toggle="modal" data-target="#delete-<?=$row->id_balita?>" href=""><button
                        class="btn btn-sm bg-red text-white">Hapus</button></a>
                  </td>
                </tr>
                <?php endforeach; ?>
              </tbody>
            </table>
          </div>
        </div>
      </div>
      <!-- /.container-fluid -->
    </div>
    <!-- /.content -->
  </div>
  <!-- /.content -->

</div>
<!-- /.content-wrapper -->

<!-- form untuk tambah data  -->
<div class="modal fade" id="tambah">
  <div class="modal-dialog tambah">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Form Tambah Data Balita</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="<?= base_url('balita/prosesbalita')?>" method="Post">
          <table class="table table-bordered table-striped table-hover" style="max-height: 300px">
            <tbody>
              <tr>
                <th style="width: 30%">
                  Nama Balita
                </th>
                <td>
                  <input type="text" class="form-control" name="nama_balita" required autofocus>
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Jenis Kelamin
                </th>
                <td>
                  <select class="form-control" required name="jk">
                    <option value="">- Pilih -</option>
                    <option value="Laki-laki">Laki-laki</option>
                    <option value="Perempuan">Perempuan</option>
                  </select>
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Umur
                </th>
                <td>
                  <input type="text" class="form-control" name="umur" required autofocus>
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Nama Orang Tua
                </th>
                <td>
                  <input type="text" class="form-control" name="nama_ortu" required autofocus>
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Berat Badan
                </th>
                <td>
                  <input type="text" class="form-control" name="berat_badan" required autofocus>
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Tinggi Badan
                </th>
                <td>
                  <input type="text" class="form-control" name="tinggi_badan" required autofocus>
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Status Gizi
                </th>
                <td>
                  <select class="form-control" required name="status_gizi">
                    <option value="">- Pilih -</option>
                    <option value="gizi_buruk">Gizi Buruk</option>
                    <option value="gizi_kurang">Gizi Kurang</option>
                    <option value="gizi_baik">Gizi Baik</option>
                    <option value="gizi_berisiko">Berisiko Gizi Lebih</option>
                    <option value="gizi_lebih">Gizi Lebih</option>
                    <option value="obesitas">Obesitas</option>
                  </select>
                </td>
              </tr>
            </tbody>
          </table>
          <input type="submit" class="btn bg-blue text-white btn-block " name="tambah" value="Simpan">
          <br><br>

          <?php echo form_close() ?>
      </div>
      <div class="modal-footer justify-content-between">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>

<!-- form untuk edit data  -->
<?php $i = 1; foreach ($list_balita as $row): ?>
<div class="modal fade" id="edit-<?=$row->id_balita?>">
  <div class="modal-dialog edit-<?=$row->id_balita?>">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Form Edit Data Balita</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <form action="<?= base_url('balita/prosesbalita')?>" method="post">
          <input type="hidden" name="id_balita" value="<?=$row->id_balita?>">
          <table class="table table-bordered table-striped table-hover" style="max-height: 300px">
            <tbody>
              <tr>
                <th style="width: 30%">
                  Nama Balita
                </th>
                <td>
                  <input type="text" class="form-control" name="nama_balita" placeholder="Masukkan Nama Balita" required
                    autofocus value="<?=$row->nama_balita?>">
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Jenis Kelamin
                </th>
                <td>
                  <select class="form-control" required name="jk">
                    <option value="">- Pilih -</option>
                    <option value="Laki-laki" <?= ($row->jk == 'Laki-laki') ? 'selected' : '' ?>>
                      Laki-laki</option>
                    <option value="Perempuan" <?= ($row->jk == 'Perempuan') ? 'selected' : '' ?>>
                      Perempuan</option>
                  </select>
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Umur (Bulan)
                </th>
                <td>
                  <input type="text" class="form-control" name="umur" placeholder="Masukkan Umur Balita" required
                    autofocus value="<?=$row->umur?>">
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Nama Orang Tua
                </th>
                <td>
                  <input type="text" class="form-control" name="nama_ortu" placeholder="Masukkan Nama Orang Tua"
                    required autofocus value="<?=$row->nama_ortu?>">
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Berat Badan (kg)
                </th>
                <td>
                  <input type="text" class="form-control" name="berat_badan" placeholder="Masukkan Berat Badan" required
                    autofocus value="<?=$row->berat_badan?>">
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Tinggi Badan (cm)
                </th>
                <td>
                  <input type="text" class="form-control" name="tinggi_badan" placeholder="Masukkan Tinggi Badan"
                    required autofocus value="<?=$row->tinggi_badan?>">
                </td>
              </tr>
              <tr>
                <th style="width: 30%">
                  Status Gizi
                </th>
                <td>
                  <select class="form-control" required name="status_gizi">
                    <option value="">- Pilih -</option>

                    <option value="gizi_buruk" <?= ($row->status_gizi == 'gizi_buruk') ? 'selected' : '' ?>>
                      Gizi Buruk</option>
                    <option value="gizi_kurang" <?= ($row->status_gizi == 'gizi_kurang') ? 'selected' : '' ?>>
                      Gizi Kurang</option>
                    <option value="gizi_baik" <?= ($row->status_gizi == 'gizi_baik') ? 'selected' : '' ?>>
                      Gizi Baik</option>
                    <option value="gizi_berisiko" <?= ($row->status_gizi == 'gizi_berisiko') ? 'selected' : '' ?>>
                      Berisiko Gizi Lebih</option>
                    <option value="gizi_lebih" <?= ($row->status_gizi == 'gizi_lebih') ? 'selected' : '' ?>>
                      Gizi Lebih</option>
                    <option value="obesitas" <?= ($row->status_gizi == 'obesitas') ? 'selected' : '' ?>>
                      Obesitas</option>

                  </select>
                </td>
              </tr>
            </tbody>
          </table>
          <input type="submit" class="btn bg-blue btn-block text-white" name="edit" value="Simpan"> <br><br>
        </form>
      </div>
      <div class="modal-footer justify-content-between">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<?php endforeach; ?>

<!-- form untuk hapus data  -->
<?php $i = 1; foreach ($list_balita as $row): ?>
<div class="modal fade" id="delete-<?=$row->id_balita?>">
  <div class="modal-dialog delete-<?=$row->id_balita?>">
    <div class="modal-content">
      <div class="modal-header">
        <h4 class="modal-title">Hapus Balita : <?=$row->nama_balita?></h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <div class="row">
          <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">

            <form action="<?= base_url('balita/prosesbalita')?>" method="Post">
              <input type="hidden" value="<?=$row->id_balita?>" name="id_balita">
              <input type="submit" class="btn bg-green btn-block " name="hapus" value="Ya">

          </div>
          <div class="col-lg-6 col-md-6 col-sm-6 col-xs-6">
            <button type="button" class="btn bg-red btn-block text-white" data-dismiss="modal">Tidak</button>
          </div>
          <?php echo form_close() ?>
        </div>
      </div>

    </div>
    <!-- /.modal-content -->
  </div>
  <!-- /.modal-dialog -->
</div>
<?php endforeach; ?>