<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>
<div class="col-12">
  <div class="card card-primary card-outline" id="content-box-1">
    <div class="card-header">
      <form role="form" method="POST" id="form-data" action="<?php echo $url_form ?>">
        <div class="row">        
          <div class="col-12 col-sm-5 col-md-5 col-lg-5">
            <div class="input-group input-group-sm">
              <div class="input-group-prepend">
                <span class="input-group-text">BPJS</span>
              </div>
              <select class="form-control form-control-sm" name="service_name" onchange="change_service(this.value)">
                <option selected hidden disabled>Pilih</option>
                <option value="pendaftaran_provider">Pendaftaran By Provider</option>
                <option value="riwayat_kunjungan">Riwayat Kunjungan</option>
              </select>
            </div>         
          </div>
          <div class="col-12 col-sm-3 col-md-3 col-lg-3" id="form_input">
          </div>
          <div class="col-12 col-sm-4 col-md-4 col-lg-4">
            <input type="hidden" name="tipe_request">
            <button type="submit" class="btn btn-success btn-sm float-sm-right"><i class="fas fa-list"></i> Tampilkan</button>
          </div>
        </div>
      </form>
    </div>
    <div class="card-body" id="content-tabel-1">
    </div>
  </div>

  <div class="card card-default" id="content-box-2">
    <div id="content-tabel-2">
    </div>                
  </div>
</div>

<script type="text/javascript">
  var base_url        = url.protocol+'<?php echo str_replace("http:", "", base_url()); ?>';
  var controller_url  = base_url+'<?php echo $this->uri->segment(1); ?>';
</script>

<script type="text/javascript">

  function change_service(value)
  {
    switch(value) {
      case 'pendaftaran_provider':
      $('#form_input').html('<input type="text" class="form-control form-control-sm cari_data" name="tglDaftar" value="<?php echo date('d-m-Y') ?>" placeholder="tanggal" /> ');
      $('#form-data').attr('action', '<?php echo $this->uri->segment(1) ?>/tabel_get_loop');
      break;
      case 'riwayat_kunjungan':
      $('#form_input').html('<input type="text" class="form-control form-control-sm cari_data" name="noKartu" placeholder="nomor kartu" /> ');
      $('#form-data').attr('action', '<?php echo $this->uri->segment(1) ?>/tabel_get');
      break;
    }
  }
  
  $(document).ready(function(){
    $('#example1').DataTable({
      "paging": true,
      "lengthChange": false,
      "searching": true,
      "ordering": true,
      "info": false,
      "autoWidth": true,
      "responsive": false,
    });
  });

  $('#form-data').submit(function(e){
    e.preventDefault();
    $.ajax({
      type: $('#form-data').attr('method'),
      url: base_url+''+$('#form-data').attr('action'),
      data:new FormData(this),
      processData:false,
      contentType:false,
      cache:false,
      async:false,
      dataType:'json',
      success: function(response)
      { 
        if(response.eror == 'success')
        {
          $('#content-tabel-1').html(response.data); 
        } 
        else notif(response.eror, response.pesan);
      },
      error: function (xhr, ajaxOptions, thrownError) {
        console.log(xhr.responseText);
      }  
    });
  })

</script>