
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCU3tdTex4BWClD0vauHsj01n2pydE0_O4&v=weekly"
      defer></script>
<script src="https://polyfill.io/v3/polyfill.min.js?features=default"></script>
<script src="<?=base_url()?>/assets/plupload/moxie.min.js"></script>
<script src="<?=base_url()?>/assets/plupload/plupload.dev.js"></script>
<script src="https://cdn.ckeditor.com/ckeditor5/36.0.1/classic/ckeditor.js"></script>

<div class="content-wrapper">
    <div class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="m-0">Detail Pangkalan</h1>
                </div><!-- /.col -->
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="<?=base_url()?>home">Home</a></li>
                    <li class="breadcrumb-item"><a href="<?=base_url()?>agen_pangkalan">Data Pangkalan</a></li>
                    <li class="breadcrumb-item active">Detail Pangkalan</li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <hr/>
    <style>
        .select2-container .select2-selection--single{
            height: 38px !important;
        }
    </style>
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <?php
                    if ($data->status == 'draft'){
                    ?>
                    <div class="alert alert-secondary alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Info</h5>
                        Pengajuan Pangkalan ini masih pada tahap draft. Silahkan lengkapi data pengajuan dan kirim pengajuan dengan menekan tombol [Kirim Pengajuan] pada menu Rekapitulasi.
                    </div>
                    <?php
                    }elseif ($data->status == 'waiting'){
                    ?>
                    <div class="alert alert-info alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Info</h5>
                        Pengajuan Pangkalan ini masuk ke dalam proses pemeriksaan. Silahkan menunggu notifikasi selanjutnya.
                    </div>
                    <?php
                    }elseif ($data->status == 'revision'){
                    ?>
                    <div class="alert alert-warning alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Alert</h5>
                        Pengajuan Pangkalan ini perlu perbaikan. Silahkan perbaiki data pengajuan dan kirim pengajuan kembali dengan menekan tombol [Kirim Pengajuan] pada menu Rekapitulasi.
                    </div>
                    <?php
                    }elseif ($data->status == 'approve'){
                    ?>
                    <div class="alert alert-success alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Aktif</h5>
                        Pangkalan ini sudah diterima dan telah aktif.
                    </div>
                    <?php
                    }elseif ($data->status == 'reject'){
                    ?>
                    <div class="alert alert-danger alert-dismissible">
                        <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                        <h5><i class="icon fas fa-info"></i> Alert</h5>
                        Pengajuan Pangkalan ini ditolak. Anda dapat melihat alasan penolakan pada bagian komentar Tim Pemeriksa pada menu Rekapitulasi.
                    </div>
                    <?php
                    }
                    ?>
                </div>
            </div>
            <div class="row">
                <div class="col-lg-12">
                    <div class="card card-primary card-outline card-tabs">
                        <div class="card-header">
                            <ul class="nav nav-tabs" id="tabs-tab" role="tablist">
                                <li class="nav-item">
                                    <a class="nav-link active" id="tabs-data-pokok-tab" data-toggle="pill" href="#tabs-data-pokok" role="tab" aria-controls="tabs-data-pokok" aria-selected="true"><i class="fas fa-users"></i> Data Pokok</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="tabs-data-pemilik-tab" data-toggle="pill" href="#tabs-data-pemilik" role="tab" aria-controls="tabs-data-pemilik" aria-selected="false"><i class="fas fa-users"></i> Data Pemilik</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="tabs-lokasi-tab" data-toggle="pill" href="#tabs-lokasi" role="tab" aria-controls="tabs-lokasi" aria-selected="false"><i class="far fa-file-alt"></i> Lokasi</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="tabs-dokumen-tab" data-toggle="pill" href="#tabs-dokumen" role="tab" aria-controls="tabs-dokumen" aria-selected="false"><i class="far fa-file-alt"></i> Dokumen</a>
                                </li>
                                <li class="nav-item">
                                    <a class="nav-link" id="tabs-rekap-tab" data-toggle="pill" href="#tabs-rekap" role="tab" aria-controls="tabs-rekap" aria-selected="false"><i class="far fa-file-alt"></i> Rekapitulasi</a>
                                </li>
                            </ul>
                        </div>
                        <div class="card-body">
                            <div class="tab-content" id="tabs-tabContent">
                                <div class="tab-pane text-left fade show active" id="tabs-data-pokok" role="tabpanel" aria-labelledby="tabs-data-pokok-tab">
                                    <form id="f1" action="#" method="post" enctype="multipart/form-data">
                                        <input type="hidden" name="id" value="<?=$data->id_pangkalan?>">
                                        <div class="form-group">
                                            <label for="id_agen">Agen</label>
                                            <span class="form-control form-control-border" id="id_agen"><?=$data->nama_perusahaan?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="id_tipe_pangkalan">Tipe Pangkalan</label>
                                            <span class="form-control form-control-border"><?=$data->nama_tipe?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="id_registrasi">ID Registrasi</label>
                                            <span class="form-control form-control-border" id="id_registrasi"><?=$data->id_registrasi?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="nama_pangkalan">Nama Pangkalan</label>
                                            <span class="form-control form-control-border"><?=$data->nama_pangkalan?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="no_telepon">Nomor Telepon</label>
                                            <span class="form-control form-control-border"><?=$data->no_telepon?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="no_sku">Nomor SKU</label>
                                            <span class="form-control form-control-border"><?=$data->no_sku?></span>
                                        </div>
                                        <div class="card">
                                            <div class="card-body d-flex">
                                                <div class="ml-2">
                                                    <p>
                                                        <b>SKU</b><br>
                                                        <?php
                                                            $status_sku = false;
                                                            if (!empty($data->sku))
                                                            {
                                                                $status_sku=true;
                                                                echo 'File : '.$data->sku;
                                                            }else{
                                                                echo 'No File Available';
                                                            }
                                                        ?>
                                                    </p>
                                                </div>
                                                <div class="ml-auto">
                                                    <?php
                                                    if (!$status_sku){
                                                    ?>
                                                    
                                                    <?php
                                                    }else{
                                                        ?>
                                                        
                                                        <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->sku?>','sku');">
                                                            <i class="fas fa-download"></i> Download
                                                        </a>
                                                        <?php
                                                    }
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label for="kuantiti">Qty Tabung / Bulan</label>
                                            <span class="form-control form-control-border"><?=$data->kuantiti?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="tipe_pembayaran">Tipe Pembayaran</label>
                                            <span class="form-control form-control-border"><?=$data->tipe_pembayaran?></span>
                                        </div>
                                    </form>
                                    <hr/>
                                    
                                </div>
                                <div class="tab-pane text-left fade" id="tabs-data-pemilik" role="tabpanel" aria-labelledby="tabs-data-pemilik-tab">
                                    <form id="f2" action="#" method="post" enctype="multipart/form-data">
                                        <input type="hidden" name="id" value="<?=$data->id_pangkalan?>">
                                        <div class="form-group">
                                            <label for="nama_pemilik">Nama Pemilik</label>
                                            <span class="form-control form-control-border"><?=$data->nama_pemilik?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="no_ktp_pemilik">Nomor KTP Pemilik</label>
                                            <span class="form-control form-control-border"><?=$data->no_ktp_pemilik?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="no_hp_pemilik">Nomor HP Pemilik</label>
                                            <span class="form-control form-control-border"><?=$data->no_hp_pemilik?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="email">Email</label>
                                            <span class="form-control form-control-border"><?=$data->email?></span>
                                        </div>
                                    </form>
                                    <hr/>
                                    
                                </div>
                                <div class="tab-pane text-left fade" id="tabs-lokasi" role="tabpanel" aria-labelledby="tabs-lokasi-tab">
                                    <form id="f3" action="#" method="post" enctype="multipart/form-data">
                                        <div class="form-group">
                                            <label for="alamat">Alamat</label>
                                            <span class="form-control form-control-border"><?=$data->alamat?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="provinsi">Provinsi</label>
                                            <span class="form-control form-control-border" id="provinsi"><?=$data->nama_provinsi?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="kabupaten">Kabupaten</label>
                                            <span class="form-control form-control-border"><?=$data->nama_kabupaten?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="kecamatan">Kecamatan</label>
                                            <span class="form-control form-control-border"><?=$data->nama_kecamatan?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="kelurahan">Kelurahan</label>
                                            <span class="form-control form-control-border"><?=$data->nama_kelurahan?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="kode_pos">Kode Pos</label>
                                            <span class="form-control form-control-border"><?=$data->kode_pos?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="lat">Latitude</label>
                                            <span class="form-control form-control-border"><?=$data->lat?></span>
                                        </div>
                                        <div class="form-group">
                                            <label for="lng">Longitude</label>
                                            <span class="form-control form-control-border"><?=$data->lng?></span>
                                        </div>
                                        <div class="form-group">
                                            <div id="map">
                                            </div>
                                        </div>
                                        <div class="card">
                                            <div class="card-body d-flex">
                                                <div class="ml-2">
                                                    <p>
                                                        <b>Foto Luar</b><br>
                                                        <?php
                                                            $status_foto_luar = false;
                                                            if (!empty($data->foto_luar))
                                                            {
                                                                $status_foto_luar=true;
                                                                ?>
                                                                <img class="img-fluid" src="<?=base_url()?>uploads/agen/pangkalan/dokumen/foto_luar/<?=$data->foto_luar?>">
                                                                <?php
                                                            }else{
                                                                echo 'No File Available';
                                                            }
                                                        ?>
                                                    </p>
                                                </div>
                                                <div class="ml-auto">
                                                    <?php
                                                    if (!$status_foto_luar){
                                                    ?>
                                                    
                                                    <?php
                                                    }else{
                                                        ?>
                                                        
                                                        <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->foto_luar?>','foto_luar');">
                                                            <i class="fas fa-download"></i> Download
                                                        </a>
                                                        <?php
                                                    }
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="card">
                                            <div class="card-body d-flex">
                                                <div class="ml-2">
                                                    <p>
                                                        <b>Foto Dalam</b><br>
                                                        <?php
                                                            $status_foto_dalam = false;
                                                            if (!empty($data->foto_dalam))
                                                            {
                                                                $status_foto_dalam=true;
                                                                ?>
                                                                <img class="img-fluid" src="<?=base_url()?>uploads/agen/pangkalan/dokumen/foto_dalam/<?=$data->foto_dalam?>">
                                                                <?php
                                                            }else{
                                                                echo 'No File Available';
                                                            }
                                                        ?>
                                                    </p>
                                                </div>
                                                <div class="ml-auto">
                                                    <?php
                                                    if (!$status_foto_dalam){
                                                    ?>
                                                    
                                                    <?php
                                                    }else{
                                                        ?>
                                                        
                                                        <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->foto_dalam?>','foto_dalam');">
                                                            <i class="fas fa-download"></i> Download
                                                        </a>
                                                        <?php
                                                    }
                                                    ?>
                                                </div>
                                            </div>
                                        </div>
                                    </form>
                                    
                                </div>
                                <div class="tab-pane text-left fade" id="tabs-dokumen" role="tabpanel" aria-labelledby="tabs-dokumen-tab">
                                    <div class="card">
                                        <div class="card-body d-flex">
                                            <div class="ml-2">
                                                <p>
                                                    <b>Upload KTP Pemilik</b><br>
                                                    <?php
                                                        $status1 = false;
                                                        if (!empty($data->ktp))
                                                        {
                                                            $status1=true;
                                                            ?>
                                                            <img class="img-fluid" src="<?=base_url()?>uploads/agen/pangkalan/dokumen/ktp/<?=$data->ktp?>">
                                                            <?php
                                                        }else{
                                                            echo 'No File Available';
                                                        }
                                                    ?>
                                                </p>
                                            </div>
                                            <div class="ml-auto">
                                                <?php
                                                if (!$status1){
                                                ?>
                                                
                                                <?php
                                                }else{
                                                    ?>
                                                    
                                                    <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->ktp?>','ktp');">
                                                        <i class="fas fa-download"></i> Download
                                                    </a>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="card">
                                        <div class="card-body d-flex">
                                            <div class="ml-2">
                                                <p>
                                                    <b>Foto Selfie KTP</b><br>
                                                    <?php
                                                        $status2 = false;
                                                        if (!empty($data->selfie_ktp))
                                                        {
                                                            $status2=true;
                                                            ?>
                                                            <img class="img-fluid" src="<?=base_url()?>uploads/agen/pangkalan/dokumen/selfie_ktp/<?=$data->selfie_ktp?>">
                                                            <?php
                                                        }else{
                                                            echo 'No File Available';
                                                        }
                                                    ?>
                                                </p>
                                            </div>
                                            <div class="ml-auto">
                                                <?php
                                                if (!$status2){
                                                ?>
                                                
                                                <?php
                                                }else{
                                                    ?>
                                                    
                                                    <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->selfie_ktp?>','selfie_ktp');">
                                                        <i class="fas fa-download"></i> Download
                                                    </a>
                                                    <?php
                                                }
                                                ?>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="tab-pane text-left fade" id="tabs-rekap" role="tabpanel" aria-labelledby="tabs-rekap-tab">
                                    <h5>Rekapitulasi</h5>
                                    <p>Pada halaman ini dapat dilihat rekapitulasi data pengajuan atau informasi pangkalan. Status pangkalan dapat dibagi menjadi  yaitu :
                                        <ul>
                                            <li>Draft, Tahap awal pengisian data pengajuan dimana agen / user dapat merubah data dan kemudian mengirimkan pengajuan untuk diperiksa.</li>
                                            <li>Menunggu Pemeriksaan, Tahap ini pengajuan akan diperiksa oleh tim pemeriksa. Agen / User akan mendapatkan notifikasi jika pengajuan telah selesai diperiksa.</li>
                                            <li>Permintaan Perbaikan, Tahap ini merupakan tahap dimana data pengajuan membutuhkan perbaikan. Agen / User dapat merubah data pengajuan sesuai dengan permintaan perbaikan dan mengajukan pemeriksaan kembali.</li>
                                            <li>Aktif, Tahap ini merupakan tahap dimana pangkalan telah dinyatakn aktif.</li>
                                            <li>Ditolak, pada tahap ini pengajuan ditolak dan tidak dapat diteruskan.</li>
                                        </ul>
                                    </p>
                                    <div class="card">
                                        <div class="card-body">
                                            <?php
                                            $status_pangkalan = '<span class="btn btn-sm btn-secondary bg-gradient-secondary">Draft</span>';
                                            if ($data->status == 'waiting')
                                            {
                                                $status_pangkalan ='<span class="btn btn-sm btn-primary bg-gradient-primary">Menunggu Pemeriksaan</span>';
                                            }elseif($data->status == 'revision'){
                                                $status_pangkalan ='<span class="btn btn-sm btn-warning bg-gradient-warning">Permintaan Perbaikan</span>';
                                            }elseif($data->status == 'reject'){
                                                $status_pangkalan = '<span class="btn btn-sm btn-danger bg-gradient-danger">Ditolak</span>';
                                            }elseif(($data->status == 'approve') || ($data->status == 'AKTIF')){
                                                $status_pangkalan = '<span class="btn btn-sm btn-success bg-gradient-success">Aktif</span>';
                                            }
                                            ?>
                                            Status Pangkalan : <?=$status_pangkalan?>
                                        </div>
                                    </div>
                                    <div class="card card-warning card-outline">
                                        <div class="card-header">
                                            <h3 class="card-title">
                                                Tim Pemeriksa
                                            </h3>
                                        </div>
                                        <div class="card-body">
                                            <table class="table">
                                                <tr>
                                                    <td width="300">Petugas</td>
                                                    <td width="5">:</td>
                                                    <td><?=$approval->nama_petugas?></td>
                                                </tr>
                                                <tr>
                                                    <td width="300">Tanggal Status</td>
                                                    <td width="5">:</td>
                                                    <td><?=$approval->tgl_status_all?></td>
                                                </tr>
                                                <tr>
                                                    <td>Komentar Tim Pemeriksaan</td>
                                                    <td>:</td>
                                                    <td><p>Petugas : <?=$komentar_latest[0]->nama?></p><p>Tanggal : <?=$komentar_latest[0]->tanggal?></p>
                                                    <p>Pesan : <br><?=$komentar_latest[0]->komentar?></p>
                                                    <hr/>
                                                    <p><button id="b_lihat_riwayat_komentar" class="btn btn-sm bg-gradient-success" data-toggle="modal" data-target="#modal-komentar">Lihat Riwayat Komentar</button></td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <div class="modal fade" id="modal-komentar" style="display: none;" aria-hidden="true">
        <div class="modal-dialog modal-xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Riwayat Komentar</h4>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                    </button>
                </div>
                <div class="modal-body">
                    <table id="tbl_data1" class="table table-striped table-bordered display compact" style="width:100%">
                        <thead>
                            <tr>
                                <th>Tanggal</th>
                                <th>Pemeriksa</th>
                                <th>Komentar</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
                <div class="modal-footer justify-content-between">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
            <!-- /.modal-content -->
        </div>
        <!-- /.modal-dialog -->
    </div>
    <style>
        #map {
            width: 100%;
            height: 500px;
        }
    </style>
    <script>
        $(document).ready(function () {
            var table_komentar;

            $('#modal-komentar').on('shown.bs.modal', function (event) {
                table_komentar = $("#tbl_data1").DataTable({
                    processing: true,
                    serverSide: true,
                    pageLength:10,
                    scrollX: true,
                    dom: "<'row mb-3'<'col-sm-12'B>>" +
                    "<'row mb-2'<'col-sm-6'f><'col-sm-6'p>>" +
                    "<'row'<'col-sm-12'tr>>" +
                    "<'row'<'col-sm-5'i><'col-sm-7'p>>",
                    language : {
                        searchBuilder: {
                            button: '<span class="fas fa-search"> Filter</span>',
                        }
                    },
                    ajax: {
                        url : '<?=base_url()?>agen_get_komentar_pengajuan_pangkalan/<?=$data->id_pangkalan?>',
                        type : 'POST'
                    },
                    columns: [
                        { data: 'tanggal' },
                        { data: 'nama' },
                        { data: 'komentar' },
                    ],
                    buttons: [
                        'searchBuilder',
                        'copyHtml5',
                        {
                            extend: 'excelHtml5',
                            text: 'Export Excel',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        },
                        {
                            extend: 'csvHtml5',
                            text: 'Export CSV',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        },
                        {
                            extend: 'pdfHtml5',
                            text: 'Export PDF',
                            orientation: 'landscape',
                            exportOptions: {
                                columns: [ ':not(.not-export)' ]
                            }
                        }
                    ]
                });
            });

            $('#modal-komentar').on('hidden.bs.modal', function (event) {
                table_komentar.destroy();
            });
        });
    </script>
    <script>
        function download_file(filename,target)
        {
            var link = document.createElement('a');
            link.download = filename;
            link.href ="<?=base_url()?>/uploads/agen/pangkalan/dokumen/"+target+"/"+filename;  
            link.click();
        }
    </script>
    <script>
        var map;
        var markers = [];
        var iconBase;
        var icons;
        $(document).ready(function () {
            function initMap() {
                map = new google.maps.Map(document.getElementById("map"), {
                    zoom: 7,
                    center: { lat: 1.9067513, lng: 99.7160549 },
                });

                iconBase =
                    "<?=base_url()?>/src/img/";
                icons = {
                    info: {
                        icon: iconBase + "logistic.png",
                    },
                };

                <?php
                if (!empty($data->lat) && !empty($data->lng))
                {
                ?>
                    var marker = new google.maps.Marker({
                        position: new google.maps.LatLng(<?=$data->lat?>, <?=$data->lng?>),
                        icon: icons['info'].icon,
                        map: map,
                        title:'Lokasi',
                    });
                    markers.push(marker);
                    map.panTo(marker.position);
                <?php
                }
                ?>

            }

            initMap();
            
            function addMarker(position, emap) {
                while (markers.length>0)
                {
                    markers[markers.length-1].setMap(null);
                    markers.pop();
                }

                var marker = new google.maps.Marker({
                    position: position,
                    map: emap,
                    icon: icons['info'].icon,
                    title:'Lokasi'
                });
                
                markers.push(marker);
                marker.setAnimation(google.maps.Animation.BOUNCE);
                map.panTo(marker.position);

                var LatLng1 = markers[0].position.toUrlValue().split(",");

                $("input[name='lat']").val(LatLng1[0]);
                $("input[name='lng']").val(LatLng1[1]);
            }
        });
    </script>
</div>