<div class="modal" tabindex="-1" role="dialog" id="<?=$id_modal?>">
  <div class="modal-dialog  modal-dialog-centered  modal-lg" role="document" style="overflow-y: initial !important">
    <div class="modal-content">
      <form id="edit">
      <div class="modal-header bg-success text-light">
        <h5 class="modal-title">Detail Evaluasi Triwulan</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body" style="height: 70vh;overflow-y: auto;">
          <div class="row">
            <div class="form-group col-md-6">
              <label for="exampleInputEmail1">KMA</label>
              <input type="hidden" id="status" name="status">
              <input type="text" class="form-control" id="kma" name="kma" readonly value="<?=$id_row?>">
              <!-- <small id="emailHelp" class="form-text text-muted">Data Akan terisi Otomatis.</small> -->
            </div>
            <div class="form-group  col-md-6">

                      <label for="bulan_kegiatan">Bulan Kegiatan </label>
                    <input type="hidden" id="tampung_bulan_kegiatan">
                      <select class="form-control" id="bulan_kegiatan" name="bulan_kegiatan[]" multiple="multiple" disabled>
                      </select>

                    </div>
            <div class="form-group  col-md-6">
              <label for="exampleFormControlTextarea1">Pencapaian</label>
              <textarea class="form-control" id="pencapaian" name="pencapaian" rows="3" readonly></textarea>
            </div>
            <div class="form-group  col-md-6">
              <label for="exampleFormControlTextarea1">Analisa Terhadap Pencapaian</label>
              <textarea class="form-control" id="atp" name="atp" rows="3"  readonly></textarea>
            </div>
            <div class="form-group  col-md-12">
              <label for="exampleFormControlTextarea1">Realisasi Kualitatif</label>
              <textarea class="form-control" id="realisasi_kualitatif" name="realisasi_kualitatif" rows="3" readonly ></textarea>
            </div>
            <div class="form-group col-md-6">
              <label for="exampleInputEmail1">Realisasi Penerimaan</label>
                      <input type="text" class="form-control timepicker" id="realisasi_penerimaan" name="realisasi_penerimaan" aria-describedby="emailHelp" placeholder=""  readonly>
                      <!-- <small id="emailHelp" class="form-text text-muted">kod</small> -->
            </div>
            <div class="form-group col-md-6">
              <label for="exampleInputEmail1">Realisasi Pengeluaran</label>
              <input type="text" class="form-control timepicker" id="realisasi_pengeluaran" name="realisasi_pengeluaran" aria-describedby="emailHelp" placeholder=""  readonly>
              <!-- <small id="emailHelp" class="form-text text-muted">kod</small> -->
            </div>
            <div class="form-group col-md-6">
              <label for="exampleInputEmail1">Analisa Keuangan</label>
              <textarea class="form-control" id="analisa_keuangan" name="analisa_keuangan" rows="3"  readonly></textarea>
              <!-- <small id="emailHelp" class="form-text text-muted">kod</small> -->
            </div>
            <div class="form-group col-md-6">
              <label for="exampleFormControlSelect1">Terlaksana</label>
              <select class="form-control" id="terlaksana" name="terlaksana" disabled>
                <option value="1">Ya</option>
                <option value="0">Tidak</option>
              </select>
            </div>

          </div>
      </div>
      <!-- <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Batal</button>
        <button type="submit" class="btn btn-info" id="btn-submit"><i class="fas fa-save"></i> Update</button>
      </div> -->
    </form>
    </div>
  </div>
</div>
<script type="text/javascript">
  $(document).ready(function(){
    var base_url = "<?=base_url()?>";
    var id_modal = "<?=$id_modal?>";
    // var time = function(){
    //   $('.timepicker').datepicker({
    //       format: 'dd MM yyyy',
    //       todayHighlight:true,
    //       toggleActive:true,
    //       daysOfWeekDisabled:'0',
    //       autoclose:true,
    //       language:'id'
    //   });
    // }
    // time();
    $.ajax({
        url             : base_url + 'pka_ev_tri/row_ev_tri', 
        type            : "POST",
        dataType        : 'json',
        data            : {kma:'<?=$id_row?>'},
        success         : function(data){

            $("#tampung_bulan_kegiatan").val(data.bulan_kegiatan)
            $("#pencapaian").val(data.pencapaian)
            $("#atp").val(data.atp)
            $("#realisasi_kualitatif").val(data.realisasi_kualitatif)
            $("#realisasi_penerimaan").val(formatRupiah(data.realisasi_penerimaan, 'Rp. '))
            $("#realisasi_pengeluaran").val(formatRupiah(data.realisasi_pengeluaran, 'Rp. '))
            $("#analisa_keuangan").val(data.analisa_keuangan)
            $("#terlaksana").val(data.terlaksana)
            $("#status").val(data.status)



            
        }
    })
      $.ajax({
        url: base_url+"Pka_ev_tri/ambil_bulan_kegiatan",
        dataType:'json',
        success:function(response){
          // alert(response)
          var data = response;
          var $id = $('#bulan_kegiatan');
          $id.empty();
          // $id.append('<option value="">- Pilih Bulan Kegiatan -</option>');
          const tbk = $("#tampung_bulan_kegiatan").val()
          if(tbk==""){
            setTimeout(function(){
              const tbk0 = $("#tampung_bulan_kegiatan").val()
              var Arraytbk = JSON.parse(tbk0);
              
              for (var i = 0; i < data.length; i++) {
                  if(Arraytbk.includes(data[i].triwulan)==true){
                      var sel = "selected";
                  }else{
                      var sel = "";
                  }
                $id.append('<option value="'+data[i].triwulan+'" title="'+data[i].triwulan+'" '+sel+'>' + data[i].triwulan + '</option>');
              }  
            }, 100);
          }else{
            var Arraytbk = JSON.parse(tbk);
              
              for (var i = 0; i < data.length; i++) {
                  if(Arraytbk.includes(data[i].triwulan)==true){
                      var sel = "selected";
                  }else{
                      var sel = "";
                  }
                $id.append('<option value="'+data[i].triwulan+'" title="'+data[i].triwulan+'" '+sel+'>' + data[i].triwulan + '</option>');
              }  
          }
          
        } ,
        error: function(jqXHR, textStatus, errorThrown) {
          // Command: toastr["error"](errorThrown, "Error");
          alert(errorThrown)
        }  
      });
    
  })

 
  $("#bulan_kegiatan").select2({

    placeholder: " Silahkan Pilih Bulan Kegiatan"

  });
  $('#<?=$id_modal?>').on('shown.bs.modal', function () {
    $('#bulan_kegiatan').select2({
        dropdownParent: $('#<?=$id_modal?>')
    });
});
 
</script>