<?php
defined('BASEPATH') OR exit('No direct script access allowed');
?>

<div class="col-12"  style="vertical-align: center;">
  <center>
    <h5>Link Verifikasi KYC </h5>
    <div class="form-group" style="width: 400px">
      <div class="input-group input-group-sm">
        <div class="input-group-prepend">
          <span class="input-group-text">Agent</span>
        </div>
        <select class="form-control form-control-sm" name="agent">
          <?php foreach ($select_dokter as $key){ ?>
            <option value="<?php echo $key->id ?>"><?php echo $key->value ?></option>
          <?php } ?>
        </select>
      </div>         
    </div>
    <button class="btn btn-primary btn-rounded" onclick="verifikasi()">Buka Link</button>
  </center>
</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); ?>';
  
  function verifikasi()
  {
    var data = {
      agent_nama: $('select[name=agent]').val(),
      agent_nik: $('select[name=agent] :selected').text()
    }; 

    $.ajax({
      url: controller_url+'/generate_link',
      type: 'POST',
      data: data,
      dataType:'json',
      success: function(response){    
        loadFormPopup(response.data.url);
      },
      error: function (xhr, ajaxOptions, thrownError) { 
        console.log(xhr.responseText);
      }
    });
  }

  function loadFormPopup(url)
  {
    let params = `scrollbars=no,resizable=no,status=no,location=no,toolbar=no,menubar=no,width=600,height=600,left=400,top=50`;

    if(url != '')
    {    
      window.open(url, "KYC", params);
    }
    else alert('LINK kosong !!! Koneksi internet terputus');
  }

  function loadFormNewTab(url) 
  {
    if(url != '')
    {      
      window.open(url,"_blank");
    }
    else alert('LINK kosong !!! Koneksi internet terputus');
  }
</script>
