<style type="text/css">
    .table > thead > tr > th {
	    vertical-align: middle;
	    text-align: center;
    }
</style>
<div class="row">
    <!-- begin col-8 -->
    <div class="col-sm-12">
        <!-- begin panel -->
        <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>
                <?= select_parameter(); ?>
                <hr>

            </div>
            <div class="panel panel-body table-responsive">
                <form method="post" action="<?= site_url('sampel/pengajuan/create_penyiapan_sampel'); ?>">
                    <div class="row mb-3" style="font-weight: bold;">
                        <!-- <div class="col-sm-2">Tanggal Penyiapan</div>
                        <div class="col-sm-10">: <?= get_str_date2($data[0]['tanggal_penyiapan']); ?></div>
                        <div class="col-sm-2">Jenis Sampel</div>
                        <div class="col-sm-10">: <?= ucwords($data[0]['jenis_sampel']); ?></div> -->
                        <div class="col-sm-12 mt-3">
                            <?php if(in_array($this->session->userdata("id_group"), [1,8])) : ?>
                                <button type="submit" id="siapkan_sampel" class="btn btn-primary">Siapkan Sampel</button>
                            <?php endif; ?>
                            <?php if(in_array($this->session->userdata("id_group"), [1,5])) : ?>
                                <a href="<?= site_url('sampel/pengajuan/verifikasi_penyiapan_sampel'); ?>" class="btn btn-primary">Verifikasi Penyiapan Sampel</a> 
                            <?php endif; ?>
                            <a href="<?= site_url('sampel/pengajuan/riwayat_penyiapan'); ?>" class="btn btn-primary">Riwayat Penyiapan Sampel</a>
                        </div>
                    </div>
                    <table class="table table-bordered table-hover table-striped table-td-valign-middle">
                        <thead class="text-midle">
                            <tr class="inverse">
                                <th rowspan="3" class="text-center">No.</th>
                                <th rowspan="3" class="text-center">Aksi</th>
                                <th rowspan="3" class="text-center">Jenis Layanan</th>
                                <th colspan="2" class="text-center">Waktu</th>
                                <th rowspan="3" class="text-center">Nomor Sampel</th>
                                <th rowspan="3" class="text-center">Bentuk/Jenis Sampel</th>
                                <th colspan="4" class="text-center">Kondisi Sampel</th>
                                <th colspan="5" class="text-center">Jenis Sampel</th>
                                <th rowspan="3" class="text-center">Jenis Grinder</th>
                                <th rowspan="3" class="text-center">Keterangan</th>
                            </tr>
                            <tr class="inverse">
                                <th rowspan="2" class="text-center">Pukul&nbsp;Mulai</th>
                                <th rowspan="2" class="text-center">Pukul&nbsp;Selesai</th>
                                <th rowspan="2" class="text-center">Cair</th>
                                <th colspan="3" class="text-center">Padat</th>
                                <th colspan="3" class="text-center">Arsip</th>
                                <th colspan="2" class="text-center">Kerja</th>
                            </tr>
                            <tr class="inverse">
                                <th class="text-center">Basah</th>
                                <th class="text-center">Lembab</th>
                                <th class="text-center">Kering</th>
                                <th class="text-center">Cair</th>
                                <th class="text-center">Tanpa Dioven</th>
                                <th class="text-center">Dioven</th>
                                <th class="text-center">Selain Uji Aflatoksin</th>
                                <th class="text-center">Uji Aflatoksin</th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php $id_check = []; ?>
                            <?php $i = 1; foreach ($data as $r) { ?>
                            <tr>
                                <?php $id_check[] = $r['id_sampel']; ?>
                                <td class="text-center"><?= $this->uri->segment(4) + $i++ ?></td>
                                <td class="text-center">
                                    <input type="checkbox" id="check_penyimpanan<?= $r['id_sampel']; ?>" onchange="c_siapkan_sampel(<?= $r['id_sampel']; ?>);" name="check_penyiapan[]" value="<?= $r['id_sampel']; ?>">
                                    <!-- <?= aksi_button('start'); ?>
                                        <li>
                                            <a href="<?= site_url('penyiapan_sampel/'.$id_uji.'/'.$r['id_sampel'].'/'.$id_status) ?>">
                                                Penyiapan Sampel
                                            </a>
                                        </li>
                                    <?= aksi_button('end'); ?> -->
                                </td>
                                <td><?= $r['nama_layanan'] ?></td>
                                <td><?= date('H:i', strtotime($r['pukul_mulai'])); ?></td>
                                <td><?= date('H:i', strtotime($r['pukul_selesai'])); ?></td>
                                <td class="text-center"><?= $r['nomor_sampel'] ?></td>
                                <td><?= $r['bentuk_jenis'] ?></td>
                                <td class="text-center"><?= $r['id_bentuk_sampel'] === '1' ? '√' : '-';?></td>
                                <td class="text-center"><?= strpos($r['id_bentuk_sampel'], '2') !== false ? '√' : '-';?></td>
                                <td class="text-center"><?= strpos($r['id_bentuk_sampel'], '3') !== false ? '√' : '-';?></td>
                                <td class="text-center"><?= strpos($r['id_bentuk_sampel'], '4') !== false ? '√' : '-';?></td>
                                <td class="text-center"><?= $r['id_penanganan_arsip'] === '1' ? '√' : '-';?></td>
                                <td class="text-center"><?= $r['id_penanganan_arsip'] === '2' ? '√' : '-';?></td>
                                <td class="text-center"><?= $r['id_penanganan_arsip'] === '3' ? '√' : '-';?></td>
                                <td class="text-center"><?= $r['id_penanganan_kerja'] === '5' ? '√' : '-';?></td>
                                <td class="text-center"><?= $r['id_penanganan_kerja'] === '6' ? '√' : '-';?></td>
                                <td class="text-center"><?= $r['nama_grinder'];?></td>
                                <td><?= $r['keterangan'] ?></td>
                            </tr>
                            <?php } ?>
                        </tbody>
                        <tfoot>

                        </tfoot>
                    </table>
                </form>
            </div>
            <?php if(!empty($is_active)) : ?>
            <?php if(!empty($id_status) && in_array((int)$id_status, array(4))) { ?>
            <div class="panel panel-footer">
            	<a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/5') ?>" class="btn btn-success">Siapkan Sampel</a>
            	<a href="#modal-alert" class="btn btn-danger" data-toggle="modal">Batalkan</a>
            </div>
            <?php }else if(!empty($id_status) && in_array((int)$id_status, array(5))){ ?>
            <div class="panel panel-footer">
                <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/6') ?>" class="btn btn-primary">Verifikasi</a>
                <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/4') ?>" class="btn btn-danger">Kembalikan ke Penyiapan Sampel</a>
            </div>
            <?php } ?>
            <?php endif; ?>
        </div>
        <!-- end panel -->
    </div>
</div>

<div class="modal fade" id="modal-alert" style="display: none;" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <div class="alert alert-danger m-b-0">
                    <p><b>Peringatan:</b> Apakah anda yakin akan membatalkan penyiapan sampel ini?</p>
                </div>
            </div>
            <div class="modal-footer">
                <a href="<?= site_url('sampel/pengajuan/siapkan_sampel/'.$id_uji.'/0') ?>" class="btn width-100 btn-sm btn-primary">Ya</a>
                <a href="javascript:;" class="btn width-100 btn-sm btn-danger" data-dismiss="modal">Tidak</a>
            </div>
        </div>
    </div>
</div>

<?php $id_check = json_encode($id_check); ?>

<script>
    $('#siapkan_sampel').hide();
    function c_siapkan_sampel()
    {
        var idcheck = <?= $id_check; ?>;
        var cc = '';
        for(var i=0; i<idcheck.length; i++) {
            if($('#check_penyimpanan'+idcheck[i]).prop('checked')){
                cc +=1;
            }else{
                cc +=0;
            }
        }

        if(cc < 1){
            $('#siapkan_sampel').hide();
        }else{
            $('#siapkan_sampel').show();
        }
    }
</script>