<?php
    $edit_value=null;
    if(isset($edit)){
        $edit_value = $edit;
    }
?>
<div class="row">
  <!-- begin col-8 -->
  <div class="col-lg-12">
      <!-- begin panel -->
      <form class="form-horizontal" method="post" name="" action="">
      <div class="panel panel-grey">
          <div class="panel-heading">
              <div class="panel-heading-btn">
                  <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-grey" data-click="panel-expand"><i class="fa fa-expand"></i></a>
                  <a href="javascript:;" class="btn btn-xs btn-icon btn-circle btn-grey" data-click="panel-remove"><i class="fa fa-times"></i></a>
              </div>
              <a onclick="goBack()" class="btn btn-primary m-b-5"><span class="fa fa-arrow-left"></span> Kembali</a>
              <hr>
          </div>
          <div class="panel-body">
              <div class="col-sm-10">
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Tanggal Penyiapan<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <div class="input-group bootstrap-timepicker">
                            <input class="form-control datepicker-default" value="<?= isset($edit  ['tanggal_penyiapan']) ? get_str_date2($edit['tanggal_penyiapan']) : date('d/m/Y'); ?>" name="tanggal_penyiapan" type="text">
                        </div>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Waktu Pukul Mulai<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <div class="input-group bootstrap-timepicker">
                            <input value="<?= isset($edit) ? $edit['pukul_mulai'] : '' ?>" name="pukul_mulai" type="text" class="form-control timepicker">
                            <span class="input-group-addon"><i class="fa fa-clock"></i></span>
                        </div>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Waktu Pukul Selesai<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <div class="input-group bootstrap-timepicker">
                            <input value="<?= isset($edit) ? $edit['pukul_selesai'] : '' ?>" class="form-control timepicker" name="pukul_selesai" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-clock"></i></span>
                        </div>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Jenis Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <?php $jenis_sampel = ['aktif', 'pasif', 'khusus']; ?>
                        <select class="form-control" name="jenis_sampel">
                            <option readonly>Pilih salah satu</option>
                            <?php foreach($jenis_sampel as $js) : ?>
                                <option <?= (isset($edit) && $edit['jenis_sampel'] == $js) ? 'selected' : ''; ?> value="<?= $js; ?>">
                                    <?= ucwords($js); ?>
                                </option>
                            <?php endforeach; ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Nomor Sampel</label>
                    <div class="col-md-7">
                        <input class="form-control" name="nomor_sampel" type="number" value="<?= $nomor_sampel; ?>" readonly>
                    </div>
                </div>

                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">
                        Bentuk/Jenis Sampel<span class="text-danger">*</span>
                    </label>
                    <div class="col-md-7">
                        <input class="form-control" name="bentuk_sampel" type="text" value="<?= $bentuk_jenis_sampel; ?>">
                    </div>
                </div>

                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Kondisi Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select name="id_bentuk_sampel" onchange="pilihJenis(this.value);" class="form-control select2" required>
                            <option></option>
                            <option <?= isset($edit['id_bentuk_sampel']) && strpos($edit['id_bentuk_sampel'], '1') !== false ? 'selected' : ''; ?> value="1">Cair</option>
                            <option <?= isset($edit['id_bentuk_sampel']) && strpos('2|3|4|', $edit['id_bentuk_sampel']) !== false ? 'selected' : ''; ?> value="Padat">Padat</option>
                        </select>
                    </div>
                </div>

                <div class="form-group m-b-11" id="jenis_padat">
                    <label class="col-md-4 col-form-label"></label>
                    <div class="col-md-7">
                        <h5>Kondisi:</h5>
                    </div>
                    <label class="col-md-4 col-form-label control-label"></label>
                    <div class="col-md-7">
                        <?php $padat = explode('|', $edit['id_bentuk_sampel']); ?>
                        <select style="width: 100%;" name="bentuk_padat[]" class="form-control select2" multiple>
                            <option></option>
                            <?php foreach ($bentuk_sampel as $r) { ?>
                                <option <?= isset($edit) && in_array($r['id'], $padat) ? 'selected' : '' ?> value="<?= $r['id'] ?>"><?= $r['nama'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Jenis Penanganan Sampel Arsip<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select name="id_penanganan_arsip" class="form-control select2 id_penanganan_arsip" required>
                            <option></option>
                            <?php foreach ($penanganan_arsip as $r) { ?>
                            <?php if($r['nama'] === 'Cair') { ?>
                                <option <?= isset($edit) && $edit['id_penanganan_arsip'] === $r['id'] ? 'selected' : ''; ?> value="<?= $r['id'] ?>"><?= $r['nama'] ?></option>
                            <?php }else { ?>
                                <option <?= isset($edit) && $edit['id_penanganan_arsip'] === $r['id'] ? 'selected' : ''; ?> value="<?= $r['id'] ?>"><?= $r['nama'] ?></option>
                            <?php } ?>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Jenis Penggunaan Sampel Kerja<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select name="id_penanganan_kerja" onchange="onPenangananKerja(this.value);" class="form-control select2 id_penanganan_kerja" required>
                            <option></option>
                            <?php foreach ($penanganan_kerja as $r) { ?>
                                <option <?= isset($edit) && $edit['id_penanganan_kerja'] === $r['id'] ? 'selected' : ''; ?> value="<?= $r['id'] ?>"><?= $r['nama'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                
                <!-- <div class="form-group m-b-11 ket_penanganan_kerja">
                    <label class="col-md-4 col-form-label control-label"></label>
                    <div class="col-md-7">
                        <h5>Ket. Penggunaan Sampel Kerja</h5>
                        <?php $ket_penanganan_kerja = array('Uji Proksimat', 'Ca', 'P', 'MBM', 'Urea', 'Asam Amino'); ?>
                        <select style="width:100%" name="ket_penanganan_kerja" class="form-control select2">
                            <option></option>
                            <?php foreach ($ket_penanganan_kerja as $r) { ?>
                                <option <?= isset($edit) && $edit['ket_penanganan_kerja'] === $r ? 'selected' : ''; ?> value="<?= $r ?>"><?= $r ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div> -->
                
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Berat Sampel<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <input class="form-control berat_sampel" name="berat_sampel" value="<?= !empty($edit) ? $edit['berat_sampel'] : $berat_sampel; ?>" type="text" placeholder="Masukkan Berat Sampel" required>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Satuan Berat<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select class="form-control satuan_sampel select2" name="satuan_sampel">
                            <option></option>
                            <option value='gram' <?= !empty($edit) || in_array('gram', [$edit['satuan_berat'], $satuan_berat]) ? 'selected' : ''; ?>>gram</option>
                            <option value='mili liter' <?= !empty($edit) || in_array('mili liter', [$edit['satuan_berat'], $satuan_berat]) ? 'selected' : ''; ?>>mili liter</option>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Kemasan<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <input class="form-control kemasan" name="kemasan" value="<?= !empty($edit) ? $edit['kemasan'] : $kemasan; ?>" type="text" placeholder="Masukkan Kemasan" required>
                    </div>
                </div>


                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Jenis Grinder<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select name="id_grinder" class="form-control select2" required>
                            <option></option>
                            <?php foreach ($grinder as $r) { ?>
                                <option <?= isset($edit) && $edit['id_grinder'] === $r['id'] ? 'selected' : ''; ?> value="<?= $r['id'] ?>"><?= $r['nama'] ?></option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Masukkan Jenis Grinder Baru</label>
                    <div class="col-md-7">
                        <input class="form-control kemasan" name="grinder_baru" type="text" placeholder="Masukkan jenis grinder baru">
                    </div>
                </div>

                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Penyimpanan Sampel Kerja<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select class="form-control select2 id_sampel_kerja" name="id_sampel_kerja" required>
                            <option></option>
                            <?php foreach ($sampel_kerja as $r) { ?>
                                <option value="<?= $r['id']; ?>" <?= !empty($edit) || in_array($r['id'], [$edit['id_sampel_kerja'], $id_sampel_kerja]) ? 'selected' : ''; ?>>
                                    <?= $r['nama']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>
                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Penyimpanan Sampel Arsip<span class="text-danger">*</span></label>
                    <div class="col-md-7">
                        <select class="form-control select2 id_sampel_arsip" name="id_sampel_arsip" required>
                            <option></option>
                            <?php foreach ($sampel_arsip as $r) { ?>
                                <option value="<?= $r['id']; ?>" <?= !empty($edit) || in_array($r['id'], [$edit['id_sampel_arsip'], $id_sampel_arsip]) ? 'selected' : ''; ?>>
                                    <?= $r['nama']; ?>
                                </option>
                            <?php } ?>
                        </select>
                    </div>
                </div>

                <div class="form-group m-b-11">
                    <label class="col-md-4 col-form-label control-label">Keterangan</label>
                    <div class="col-md-7">
                        <input class="form-control" name="keterangan" value="<?= isset($edit) ? $edit['keterangan'] : ''; ?>" type="text" placeholder="Masukkan keterangan">
                    </div>
                </div>

            </div>
        </div>
        <div class="panel panel-footer">
          <div class="col-sm-10">
            <div class="form-group m-b-11">
                <label class="col-md-4 col-form-label control-label"></label>
                <div class="col-md-7">
                    <button type="submit" class="btn btn-md btn-success">Simpan</button>
                    <button type="reset" class="btn btn-md btn-warning">Reset</button>
                    <a onclick="goBack();" class="btn btn-md btn-danger">Batal</a>
                </div>
            </div>
          </div>
        </div>
      </div>
      </form>
  </div>
</div>

<script type="text/javascript">
    <?php if(isset($edit['id_penanganan_kerja']) && '5' == $edit['id_penanganan_kerja']) { ?>
      $('.ket_penanganan_kerja').show();
    <?php }else { ?>
      $('.ket_penanganan_kerja').hide();
    <?php } ?>

    <?php if(isset($edit['id_bentuk_sampel']) && strpos('2|3|4|', $edit['id_bentuk_sampel']) !== false) { ?>
        $('#jenis_padat').show();
    <?php }else { ?>
        $('#jenis_padat').hide();
    <?php } ?>
    function pilihJenis(x){
        if(x === 'Padat'){
            $('#jenis_padat').show();
        }else{
            $('#jenis_padat').hide();
        }

        $.post( "<?= site_url('sampel/pengajuan/get_penanganan_sampel_arsip') ?>", { type: x}, function( data ) {
            $(".id_penanganan_arsip").html(data);
        });
    }

    function onPenangananKerja(x){
      if(x == '5'){
        $('.ket_penanganan_kerja').show();
      } else{
        $('.ket_penanganan_kerja').hide();
      }
    }

</script>
