<!-- <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.css" /> -->

<div class="row" id="portlet-content">
  <div class="col-md-12">
    <div class="portlet light" style="position:relative">
 
      <div class="portlet-body form" id="page-content" style="display:none">
        <form action="<?= site_url('front_office/'.$controller_dir.$controller.'/edit_data_proses') ?>" method="post" id="<?=$controller?>" enctype="multipart/form-data" class="horizontal-form">
          <input type="hidden" name="id_re_pasien" value="<?=$id_re_pasien?>">

          <div class="form-body">
            <div class="alert alert-danger display-hide" style="display:none;" id="error">
              <button class="close" data-close="alert"></button>
              <span id="error-text"></span>
            </div>
            
                  <h4 class="form-section" style="margin:15px 0px 15px 0px !important; padding-bottom:0px !important; font-size:13px !important"><i class="fa fa-bookmark"></i> &nbsp; <strong> Type Penanganan </strong><hr style="margin:10px 0px 0px 0px !important"> </h4>
                  <div class="row" style="margin-top:15px !important; margin-bottom:10px !important;">

                    <div class="col-md-6">
                      <div class="form-group" id="form_type_pasien" >
                        <label for="type_pasien" class="control-label">Type Pasien <span class="required">* </span></label>
                        <select id="type_pasien" name="type_pasien" class="form-control" <?=$disabled?> >
                          <option value=""></option>
                          <?php foreach ($this->Content_m->select_db('bbmc_re_tipe_pasien')->result() as $key) { ?>
                              <option value="<?=$key->id_tipe_pasien?>" <?=$get->id_type_pasien == $key->id_tipe_pasien?'selected':''?>><?=$key->tipe_pasien?></option>
                          <?php }?>
                                 
                        </select>
                        <span id="error_type_pasien" class="help-block"></span>
                      </div>
                    </div>


                    <div class="col-md-6" >
                      <div class="form-group" id="form_id_perusahaan" style="<?=$get->id_type_pasien>=3?'display: block;':'display: none'?>">
                        <label for="id_perusahaan" class="control-label">Perusahaan </label>
                        <select id="id_perusahaan" name="id_perusahaan" class="form-control" <?=$disabled?>>
                          <option value=""></option>
                          <?php foreach ($this->Content_m->select_db('bbmc_re_perusahaan')->result() as $key ) { ?>
                              <option value="<?=$key->id_perusahaan?>" <?=$get->id_perusahaan==$key->id_perusahaan?'selected':''?>><?=$key->perusahaan?></option>
                          <?php }?>
                        </select>
                        <span id="error_id_perusahaan" class="help-block"></span>
                      </div>
                    </div>

                    <div class="col-md-6">
                      <div class="form-group" id="form_no_kartu" style="<?=$get->id_type_pasien==2?'display: block;':'display: none'?>">
                        <label for="no_kartu" class="control-label">No Kartu</label>
                        <input type="text" id="no_kartu" name="no_kartu" class="form-control" placeholder="Nomor Kartu Asuransi" value="<?=$get->id_nmr_asuransi?>" <?=$disabled?>>
                        <span id="error_no_kartu" class="help-block"></span>
                      </div>
                    </div>

                  </div>

                  <h4 class="form-section" style="margin:15px 0px 0px 0px !important; padding-bottom:0px !important; font-size:13px !important"><i class="fa fa-bookmark"></i> &nbsp; <strong> Informasi Pasien </strong><hr style="margin:10px 0px 0px 0px !important"> </h4>
                  <div class="row" style="margin-top:15px !important;">
                    <div class="col-md-6">
                      <div class="form-group" id="form_nrm">
                        <label for="nrm" class="control-label">Nomor Rekam Medis </label>
                        <div class="input-group">
                            <span class="input-group-addon">
                                BBMC -
                            </span>
                            <input type="text" id="nrm" name="nrm" class="form-control"  placeholder="Nomor Rekam Medis" value="<?=$get->nrm?>" <?=$disabled?>>
                        </div>                        
                        <span id="error_nrm" class="help-block"></span>
                      </div>
                    </div>   
                   
                    <div class="col-md-6">
                      <div class="form-group" id="form_tgl_registrasi">
                        <label for="tgl_registrasi" class="control-label">Tgl Registrasi </label>

                        <input type="text" id="datepicker_tglreg" name="tgl_registrasi" class="form-control"  placeholder="Tanggal Registrasi" value="<?=$get->tgl_registrasi?>" <?=$disabled?>>
     
                        <span id="error_tgl_registrasi" class="help-block"></span>                        
                      </div>
                    </div>              

                    <div class="col-md-6">
                      <div class="form-group" id="form_tgl_registrasi">
                        <label for="tgl_registrasi" class="control-label">No KTP </label>

                        <input type="text"  name="no_ktp" class="form-control"  placeholder="No KTP" value="<?=$get->no_ktp?>">
     
                        <span id="error_tgl_registrasi" class="help-block"></span>                        
                      </div>
                    </div>                 

                  </div>
                
                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group" id="form_nm_pasien">
                        <label for="nm_pasien" class="control-label">Nama </label>
                        <input type="text" id="nm_pasien" name="nm_pasien" class="form-control" placeholder="Nama Pasien" value="<?=$get->nama_pasien?>" <?=$disabled?>>
                        <span id="error_nm_pasien" class="help-block"></span>
                      </div>
                    </div>
                  
                  <div class="col-md-6">
                      <div class="form-group" id="form_alamat_pasien">
                        <label for="alamat_pasien" class="control-label">Alamat </label>
                        <input type="text" id="alamat_pasien" name="alamat_pasien" class="form-control" placeholder="Alamat Pasien" value="<?=$get->alamat?>" <?=$disabled?>>
                        <span id="error_alamat_pasien" class="help-block"></span>
                      </div>
                    </div>                    
                  </div>

                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group" id="form_tmpt_lahir">
                        <label for="tmpt_lahir" class="control-label">Tempat Lahir </label>
                        <input type="text" id="tmpt_lahir" name="tmpt_lahir" class="form-control" placeholder="Tempat Lahir" value="<?=$get->tmpt_lahir?>" <?=$disabled?>>
                        <span id="error_tmpt_lahir" class="help-block"></span>
                      </div>
                    </div>
                  
                    <div class="col-md-6">
                      <div class="form-group" id="form_tgl_lahir">
                        <label for="tgl_lahir" class="control-label">Tanggal Lahir </label>
                        
                            <input type="text" id="datepicker_tgllhr" name="tgl_lahir" class="form-control" placeholder="Tanggal Lahir"  value="<?=$get->tgl_lahir?>" <?=$disabled?>>
                                        
                        <span id="error_tgl_lahir" class="help-block"></span>
                      </div>
                    </div>                    
                  </div>
                  
                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group" id="form_umur">
                        <label for="umur" class="control-label">Umur</label><br>
                        <div class="col-md-6" style="padding:0px 10px 0px 0px !important;"> 
                          <div class="input-group">
                            <input type="number" id="umur_tahun" name="umur_tahun" class="form-control" value="<?=$get->umur_tahun?>" <?=$disabled?>> 
                            <span class="input-group-addon"> Tahun </span>  
                          </div>                        
                          <span id="error_umur_tahun" class="help-block"></span>
                        </div>

                        <div class="col-md-6" style="padding:0px 0px 0px 10px !important;"> 
                          <div class="input-group">
                            <input type="number" id="umur_bulan" name="umur_bulan" class="form-control" value="<?=$get->umur_bulan?>" <?=$disabled?>> 
                            <span class="input-group-addon"> Bulan </span>  
                          </div> 
                          <span id="error_umur_bulan" class="help-block"></span>
                        </div>
                      </div>
                    </div>
                  
                    <div class="col-md-6">
                      <div class="form-group" id="form_jns_kel">
                        <label for="jns_kel" class="control-label">Jenis Kelamin </label>
                        <select id="jns_kel" name="jns_kel" style="width:100%" <?=$disabled?>>
                          <option value=""></option>
                          <option value="L" <?=$get->jenis_kelamin=='L'?'selected':''?> >Laki-laki</option>
                          <option value="P" <?=$get->jenis_kelamin=='P'?'selected':''?>>Perempuan</option>
                        </select>                        
                        <span id="error_jns_kel" class="help-block"></span>
                      </div>
                    </div>                    
                  </div>  
                  
                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group" id="form_status">
                        <label for="status" class="control-label">Status </label>
                        <select id="status" name="status" style="width:100%" <?=$disabled?>>
                          <option value=""></option>
                          <?php foreach ($this->Content_m->select_db('bbmc_re_status_marital')->result() as $key ) { ?>
                              <option value="<?=$key->id_status_marital?>" <?=$get->id_status==$key->id_status_marital?'selected':''?>><?=$key->status_marital?></option>
                          <?php }?>
                        </select>
                        <span id="error_status" class="help-block"></span>
                      </div>
                    </div>
                    <div class="col-md-6">
                      <div class="form-group" id="form_id_agama">
                        <label for="id_agama" class="control-label">Agama </label>
                        <select id="id_agama" name="id_agama" class="form-control" <?=$disabled?>>
                            <option value=""></option>
                           
                        </select>
                        <span id="error_id_agama" class="help-block"></span>
                      </div>
                    </div>
                    <div class="col-md-6">
                      <div class="form-group" id="form_no_tel">
                          <label for="no_tel" class="control-label">Telepon</label>
                          
                              <input type="text" id="no_tel" name="no_tel" class="form-control" placeholder="No. Telepon" value="<?=$get->telpon?>" <?=$disabled?>>
                          
                          <span id="error_no_tel" class="help-block"></span>
                      </div>
                    </div> 
                    <div class="col-md-6">
                      <div class="form-group" id="form_email">
                          <label for="email" class="control-label">Email</label>
                          
                              <input type="text" id="email" name="email" class="form-control" placeholder="Email" value="<?=$get->email?>" <?=$disabled?>>
                          
                          <span id="error_email" class="help-block"></span>
                      </div>
                    </div>                                        
                  </div>                  

                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group" id="form_gol_darah">
                        <label for="gol_darah" class="control-label">Golongan Darah </label>
                        <select id="gol_darah" name="gol_darah" class="form-control" <?=$disabled?>>
                          <option value=""></option>
                          <option value="A" <?=$get->gol_darah=='A'?'selected':''?> >Gol Darah A </option>
                          <option value="B" <?=$get->gol_darah=='B'?'selected':''?>>Gol Darah B</option>
                          <option value="O" <?=$get->gol_darah=='O'?'selected':''?>>Gol Darah O</option>
                          <option value="AB" <?=$get->gol_darah=='AB'?'selected':''?>>Gol Darah AB</option>
                        </select>
                        <span id="error_gol_darah" class="help-block"></span>
                      </div>
                    </div>
                    <div class="col-md-6">
                      <div class="form-group" id="form_kebangsaan">
                        <label for="kebangsaan" class="control-label">Kebangsaan </label>
                        <select id="kebangsaan" name="kebangsaan" class="form-control" <?=$disabled?>>
                          <option value="wni" <?=$get->kebangsaan=='wni'?'selected':''?> >Warga Negara Indonesia (WNI) </option>
                          <option value="wna" <?=$get->kebangsaan=='wna'?'selected':''?>>Warga Negara Asing (WNA)</option>
                        </select>
                        <span id="error_kebangsaan" class="help-block"></span>
                      </div>
                    </div>
                  </div>

                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group" id="form_id_jenjang_pendidikan">
                        <label for="id_jenjang_pendidikan" class="control-label">Pendidikan</label>
                        <select id="id_jenjang_pendidikan" name="id_jenjang_pendidikan" class="form-control" <?=$disabled?>>
                            <option value=""></option>
                        </select>
                        <span id="error_id_jenjang_pendidikan" class="help-block"></span>
                      </div>
                    </div>
                    <div class="col-md-6">
                      <div class="form-group" id="form_id_pekerjaan">
                        <label for="id_pekerjaan" class="control-label">Pekerjaan</label>
                        <select id="id_pekerjaan" name="id_pekerjaan" class="form-control" <?=$disabled?>>
                            <option value=""></option>
                        </select>
                        <span id="error_id_pekerjaan" class="help-block"></span>
                      </div>
                    </div>
                  </div>

                  <h4 class="form-section" style="margin:15px 0px 0px 0px !important; padding-bottom:0px !important; font-size:13px !important"><i class="fa fa-bookmark"></i> &nbsp; <strong> Detail Alamat </strong><hr style="margin:10px 0px 0px 0px !important"> </h4>
                  <div class="row" style="margin-top:15px !important;">
                    <div class="col-md-6">
                      <div class="form-group" id="form_banjar">
                        <label for="banjar" class="control-label">Banjar </label>
                        <input type="text" id="banjar" name="banjar" class="form-control" placeholder="Alamat Banjar Pasien" value="<?=$get->banjar?>" <?=$disabled?>>
                        <span id="error_banjar" class="help-block"></span>
                      </div>
                    </div>
                    <div class="col-md-6">
                      <div class="form-group" id="form_desa">
                        <label for="desa" class="control-label">Desa </label>
                        <input type="text" id="desa" name="desa" class="form-control" placeholder="Alamat Desa Pasien" value="<?=$get->desa?>" <?=$disabled?>>
                        <span id="error_desa" class="help-block"></span>
                      </div>
                    </div>
                  </div>
                  <div class="row">
                    <div class="col-md-6">
                      <div class="form-group" id="form_id_wil_kec">
                        <label for="id_wil_kec" class="control-label">Kecamatan </label>
                        <select id="id_wil_kec" name="id_wil_kec" class="form-control" placeholder="Alamat Kecamatan Pasien" <?=$disabled?>>
                          <option value=""></option>
                          <?php if($get->id_kecamatan!=''){ ?>
                          <option value="<?=$get->id_kecamatan?>" selected><?=$this->Content_m->get_value('bbmc_re_wilayah','id_wil',$get->id_kecamatan,'nm_wil')?></option>
                          <?php }?>
                        </select>
                        <span id="error_id_wil_kec" class="help-block"></span>
                      </div>
                    </div>
                    <div class="col-md-6">
                      <div class="form-group" id="form_id_wil_kab">
                        <label for="id_wil_kab" class="control-label">Kabupaten </label>
                        <select id="id_wil_kab" name="id_wil_kab" class="form-control" placeholder="Alamat Kabupaten Pasien" <?=$disabled?> >
                          <option value=""></option>
                          <?php if($get->id_kabupaten!=''){ ?>
                          <option value="<?=$get->id_kabupaten?>" selected><?=$get->id_kabupaten?></option>
                          <?php }?>
                        </select>
                        <span id="error_id_wil_kab" class="help-block"></span>
                      </div>
                    </div>
                    <div class="col-md-6">
                      <div class="form-group" id="form_id_wil_prov">
                        <label for="id_wil_prov" class="control-label">Provinsi </label>
                        <select id="id_wil_prov" name="id_wil_prov" class="form-control" placeholder="Alamat Provinsi Pasien" <?=$disabled?> >
                          <option value=""></option>
                          <?php if($get->id_provinsi!=''){ ?>
                          <option value="<?=$get->id_provinsi?>" selected><?=$get->id_provinsi?></option>
                          <?php }?>
                        </select>

                        <span id="error_id_wil_prov" class="help-block"></span>
                      </div>
                    </div>
                  </div>

          </div>
          <?php if($disabled == ''){ ?>
          <div class="form-actions right">
            <a type="button" class="btn default" href="<?= site_url('front_office/'.$controller_dir.$controller) ?>">Kembali</a>
            <button type="submit" class="btn green"><i class="fa fa-refresh"></i> Update</button>
          </div>
          <?php }?>
        </form>
      </div>
      <?php $this->load->view('front_office/include/loading'); ?>
    </div>
  </div>
</div>

<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/jquery/latest/jquery.min.js"></script> -->
<!-- <script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/daterangepicker/daterangepicker.min.js"></script> -->
<script>
  $(document).ready(function() {
    /*-------------Datepicker-------------*/
    // $('#datepicker_tglreg').daterangepicker({
    //     singleDatePicker: true,
    //     showDropdowns: true,
    //     minYear: 1901        
    //   },
    //   function (start) {
    //       $('#datepicker_tglreg').html(start.format('MMMM D, YYYY'));
    //   }
    // );
    //Set the initial state of the picker label
    //$('#datepicker_tglreg').html(moment().subtract('days', 29).format('MMMM D, YYYY'));
    
    $('#datepicker_tglreg').datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: "-60:+0",
        dateFormat: 'yy-mm-dd'
    });

    $('#datepicker_tgllhr').datepicker({
        changeMonth: true,
        changeYear: true,
        yearRange: "-60:+0",
        dateFormat: 'yy-mm-dd'
    });

    $('#datepicker_tgllhr').change(function(){
      var valu = $(this).val();
     // alert(valu);
      var dataString = 'id='+ valu;
      $.ajax({
          type: "POST",
          url: '<?= site_url('front_office/ajax/get_datediff') ?>',
          data: dataString,
          success: function(data)
          {
            data = JSON.parse(data);
            //$(".sms_change").val(data);
            //alert(data[0]);
            //alert(data[1]);
            $("#umur_tahun").val(data[0]);
            $("#umur_bulan").val(data[1]);
          }
      }); 

    });


    $("#type_pasien").change(function() {
      var vall = $(this).val();
      //alert(vall);
      if (vall == '1') {
        $('#form_id_perusahaan').css('display', 'none');
        $('#form_no_kartu').css('display', 'none');      
      } else if (vall == '2') {
        $('#form_id_perusahaan').css('display', 'none');
        $('#form_no_kartu').css('display', 'none'); 
      } else if (vall == '3') {  
        $('#form_id_perusahaan').css('display', 'block');
        $('#form_no_kartu').css('display', 'block');  
        //$('#no_kartu').attr('required', true);
        $('#no_kartu').val('');  
        //$('#id_perusahaan').attr('required', true);
        $('#id_perusahaan').val('');  
      } else if (vall == '4') {
        $('#form_id_perusahaan').css('display', 'none');
        $('#form_no_kartu').css('display', 'none'); 
      } else if (vall == '5') {
        $('#form_id_perusahaan').css('display', 'none');
        $('#form_no_kartu').css('display', 'none'); 
      } else if (vall == '6') {
        $('#form_id_perusahaan').css('display', 'none');
        $('#form_no_kartu').css('display', 'none'); 
      }

    });   
    
    $("#id_perusahaan").select2({
      placeholder: "Pilih Perusahaan Penanggung",
      
      language: "id"
    });

    $("#type_pasien").select2({
      placeholder: "Pilih Type Pasien",
      
      language: "id"
    });      

    $("#jns_kel").select2({
      placeholder: "Pilih Jenis Kelamin",
      
      language: "id"
    });
    
    $("#status").select2({
      placeholder: "Pilih Status",
      
      language: "id"
    });    

    $("#id_agama").select2({
      placeholder: "Pilih Agama",
      
      language: "id",
      data: <?=$agama?>
    });
    $("#id_agama").val("<?=$get->id_agama?>").trigger('change');

    $("#gol_darah").select2({
      placeholder: "Pilih Golongan Darah",
      
      language: "id"
    });

    $("#kebangsaan").select2({
      placeholder: "Pilih Kebangsaan",
      
      language: "id"
    });

    $("#id_pekerjaan").select2({
      placeholder: "Pilih Pekerjaan",
      
      language: "id",
      data: <?=$pekerjaan?>
    }); 
    $("#id_pekerjaan").val("<?=$get->id_pekerjaan?>").trigger('change');  
    
    $("#id_jenjang_pendidikan").select2({
      placeholder: "Pilih Jenjang Pendidikan",
      
      language: "id",
      data: <?=$pendidikan?>
    });         
    $("#id_jenjang_pendidikan").val("<?=$get->id_pendidikan?>").trigger('change');   

    $("#id_wil_kec").select2({
      placeholder: "Pilih Alamat Kecamatan",
      
      language: "id"
    }); 


    $("#id_wil_kab").select2({
      placeholder: "Pilih Alamat Kabupaten",
      
      language: "id"
    }); 

    $("#id_wil_prov").select2({
      placeholder: "Pilih Alamat Provinsi",
      
      language: "id"
    }); 

    $("#id_wil_kec").select2({
          placeholder: "Kecamatan",
          language: "id",
          ajax: {
            url: "<?=site_url('front_office/ajax/select2_wilayah')?>",
            dataType: 'json',
            delay:500,
            type:"POST",
            data: function(params) {
                return {
                    term: params.term || '',
                    page: params.page || 1
                }
            }
          },
          escapeMarkup: function (markup) {return markup;},
          minimumInputLength: 1,
          templateResult: function(repo) {
            if(repo.loading)
                return repo.text;
            return repo.value;
          },
          templateSelection: function(repo){return repo.value || repo.text;}
        }); 

        $('#id_wil_kec').on('select2:select', function(e) {
            var value_string = e.params.data.value;
            var id_string = e.params.data.id;
            var part = value_string.split('-');
            var kec_val = part[0];
            var kab_val = part[1];
            var prov_val = part[2];
            $('#id_wil_kec').append(`<option value="${id_string}" selected> ${kec_val} </option>`);
            $('#id_wil_kab').append(`<option value="${kab_val}" selected> ${kab_val} </option>`);
            $('#id_wil_prov').append(`<option value="${prov_val}" selected> ${prov_val} </option>`);
        });

    $("#loading-content,#loading").fadeOut("fast", function() {
      $("#page-content").fadeIn("fast");
    });

  });
</script>
<?php $this->load->view('front_office/script/form_data'); ?>