<script type="text/javascript">

</script>
<body>
  <main id="main" class="main">

    <!--PAGE TABEL ADMIN-->
    <section class="section dashboard">
      <div class="row">
        <div class="col-lg-12">
          <div class="card">
            <div class="card-body">
              <h5 class="card-title">TABEL REVISI DATA ALUMNI</h5>
              <table id="tabel_rev_alumni" class="table display row-border table-hover">
                <thead>
                  <tr>   
                    <th>NAMA</th>
                    <th>MASUK</th>
                    <th>LULUS</th>
                    <th>JURUSAN</th>
                    <th>EMAIL</th>
                  </tr>
                </thead>
                <tbody>
                  <?php foreach ($data_alumni as $data) : $username = $data['email']; 
                    if($data['status'] == 1){
                      $data['status'] = "<p style='font-size:21px;'><i style='color:#22bb33;' class='bi bi-check-circle-fill'></i></p>";
                    }else if($data['status'] == 2){
                      $data['status'] = "<p style='font-size:21px;'><i style='color:#bb2124;' class='bi bi-x-circle-fill'></i></p>";
                    }else{
                      $data['status'] = "<p style='font-size:21px;'><i style='color:#f0ad4e;' class='bi bi-clock-fill'></i></p>";
                    }   
                  ?> 
                    <tr>
                      <td><?php echo $data['nama'] ?></td>
                      <td style="text-align: center;"><?php echo $data['th_masuk'] ?></td>
                      <td style="text-align: center;"><?php echo $data['th_lulus'] ?></td>
                      <td><?php echo $data['jurusan'] ?></td>
                      <td style="text-align: center;"><?php echo $data['status'] ?></td>
                    </tr>
                  <?php endforeach; ?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </section>
    <!--END PAGE TABEL ADMIN-->

    <!--MODAL DETAIL-->
    <div class="modal fade " id="modalz" tabindex="-1">
      <div class="modal-dialog">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title"><b>DETAIL ALUMNI</b></h5>
            <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
          </div>
          <div id="" class="modal-body">
            <table class="table">
                <tr>
                    <td>Foto</td>
                    <td>:</td>
                    <td><img id="alumni_foto" width="70px" height="70px"></td>
                </tr>
                <tr>
                    <td>Nama</td>
                    <td>:</td>
                    <td id="alumni_nama"></td>
                </tr>
                <tr>
                    <td>Tahun Masuk</td>
                    <td>:</td>
                    <td id="alumni_th_masuk"></td>
                </tr>
                <tr>
                    <td>Tahun Lulus</td>
                    <td>:</td>
                    <td id="alumni_th_lulus"></td>
                </tr>
                <tr>
                    <td>Jurusan</td>
                    <td>:</td>
                    <td id="alumni_jurusan"></td>
                </tr>
                <tr>
                    <td>Alamat</td>
                    <td>:</td>
                    <td id="alumni_alamat"></td>
                </tr>
                <tr>
                    <td>Telepon</td>
                    <td>:</td>
                    <td id="alumni_telp"></td>
                </tr>
                <tr>
                    <td>Email</td>
                    <td>:</td>
                    <td id="alumni_email"></td>
                </tr>
                <tr>
                    <td>Profesi</td>
                    <td>:</td>
                    <td id="alumni_profesi"></td>
                </tr>
                <tr>
                    <td>Alamat Kantor</td>
                    <td>:</td>
                    <td id="alumni_alamat_kantor"></td>
                </tr>
            </table>
          </div>
          <div class="modal-footer">
            <button type="submit" class="btn btn-success" data-bs-dismiss="modal" onclick="terimaAlumni(alumni_email)">TERIMA</button>
            <button type="submit" class="btn btn-danger" data-bs-dismiss="modal" onclick="tolakAlumni(alumni_email)">TOLAK</button>
          </div>
        </div>
      </div>
    </div>
    <!--END MODAL DETAIL-->
    
  </main>
  <script type="text/javascript"> 
    function viewDetail(username){
      $.ajax({
        url: '<?php echo base_url() . "alumni/detail_alumni/"?>'+encodeURIComponent(username),
        success: function(response) {
            const responseJSON = JSON.parse(response);
            //console.log(responseJSON);
            $('#alumni_foto').attr('src','<?php echo base_url() . "assets/materi/foto_alumni/"?>'+responseJSON.foto)
            $('#alumni_nama').html(responseJSON.nama)
            $('#alumni_th_masuk').html(responseJSON.th_masuk)
            $('#alumni_th_lulus').html(responseJSON.th_lulus)
            $('#alumni_jurusan').html(responseJSON.jurusan)
            $('#alumni_alamat').html(responseJSON.alamat)
            $('#alumni_telp').html(responseJSON.telp)
            $('#alumni_email').html(responseJSON.email)
            $('#alumni_profesi').html(responseJSON.profesi)
            $('#alumni_alamat_kantor').html(responseJSON.alamat_kantor)
            $('#alumni_status').html(responseJSON.status)
            $('#modalz').modal('show');
        },
        error: function(error) {
            console.error('Error:', error);
        }
      });
    }
  </script> 

  <script type="text/javascript"> 
    function terimaAlumni(alumni_email){
      let emailz = document.getElementById("alumni_email").innerHTML;
      //alert(emailz);
      $.ajax({
        url: '<?php echo base_url() . "admin/terima_alumni/"?>'+encodeURIComponent(emailz),
        success: function(response) {
          alert("Data berhasil diterima.")
          window.location.assign("<?php echo base_url();?>admin");
          //console.log(emailz);
        },
        error: function(error) {
            console.error('Error:', error);
            console.log('Error parsing JSON:', error, data);
        }
      });
    }
  </script>

  <script type="text/javascript"> 
    function tolakAlumni(alumni_email){
      let emailz = document.getElementById("alumni_email").innerHTML;
      //alert(emailz);
      $.ajax({
        url: '<?php echo base_url() . "admin/tolak_alumni/"?>'+encodeURIComponent(emailz),
        success: function(response) {
          alert("Data berhasil ditolak.")
          window.location.assign("<?php echo base_url();?>admin");
          //console.log(emailz);
        },
        error: function(error) {
            console.error('Error:', error);
            console.log('Error parsing JSON:', error, data);
        }
      });
    }
  </script>

</body>
</html>