
<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>

<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">Data Agen</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 active">View Detail Agen</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">
                    <div class="card">
                        <div class="card-body">
                            <div class="row">
                                <div class="col-lg-3 col-sm-3">
                                    <div class="nav flex-column nav-tabs h-100" id="vert-tabs-tab" role="tablist" aria-orientation="vertical">
                                        <a class="nav-link active" id="vert-tabs-data-pokok-tab" data-toggle="pill" href="#vert-tabs-data-pokok" role="tab" aria-controls="vert-tabs-data-pokok" aria-selected="true"><i class="fas fa-users"></i> Data Pokok</a>
                                        <a class="nav-link" id="vert-tabs-lokasi-tab" data-toggle="pill" href="#vert-tabs-lokasi" role="tab" aria-controls="vert-tabs-lokasi" aria-selected="false"><i class="far fa-file-alt"></i> Lokasi</a>
                                        <a class="nav-link" id="vert-tabs-dokumen-tab" data-toggle="pill" href="#vert-tabs-dokumen" role="tab" aria-controls="vert-tabs-dokumen" aria-selected="false"><i class="far fa-file-alt"></i> Dokumen</a>
                                    </div>
                                </div>

                                <div class="col-lg-9 col-sm-9">
                                    <div class="tab-content" id="vert-tabs-tabContent">
                                        <div class="tab-pane text-left fade show active" id="vert-tabs-data-pokok" role="tabpanel" aria-labelledby="vert-tabs-data-pokok-tab">
                                            <div class="card card-outline card-success">
                                                <div class="card-header">
                                                    <div class="card-title">
                                                        Data Pokok Agen
                                                    </div>
                                                </div>
                                                <div class="card-body">
                                                    <form id="f1" action="#" method="post" enctype="multipart/form-data">
                                                        <input type="hidden" name="id" value="<?=$data->id_agen?>">
                                                        <div class="form-group">
                                                            <label for="nomor">Nomor</label>
                                                            <span class="form-control form-control-border" id="nomor"><?=$data->nomor?></span>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="nama_perusahaan">Nama Perusahaan</label>
                                                            <span class="form-control form-control-border" id="nama_perusahaan"><?=$data->nama_perusahaan?></span>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="nama_pemohon">Nama Pemohon</label>
                                                            <span class="form-control form-control-border" id="nama_pemohon"><?=$data->nama_pemohon?></span>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="sold_id">Sold ID</label>
                                                            <span class="form-control form-control-border" id="sold_id"><?=$data->sold_id?></span>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="email">Email</label>
                                                            <span class="form-control form-control-border" id="email"><?=$data->email?></span>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="password">Password</label>
                                                            <span class="form-control form-control-border" id="password">****************</span>
                                                        </div>
                                                        <div class="form-group">
                                                            <label for="no_hp">Nomor HP</label>
                                                            <span class="form-control form-control-border" id="no_hp"><?=$data->no_hp?></span>
                                                        </div>
                                                    </form>
                                                </div>
                                                <div class="card-footer text-right">
                                                    
                                                </div>
                                            </div>
                                        </div>
                                        <div class="tab-pane text-left fade" id="vert-tabs-lokasi" role="tabpanel" aria-labelledby="vert-tabs-lokasi-tab">
                                            <div class="card card-outline card-info">
                                                <div class="card-header">
                                                    <div class="card-title">
                                                        Lokasi
                                                    </div>
                                                </div>
                                                <div class="card-body">
                                                    <div class="card">
                                                        <div class="card-body">
                                                            <form id="f2" action="#" method="post" enctype="multipart/form-data">
                                                                <div class="form-group">
                                                                    <label for="alamat">Alamat</label>
                                                                    <span class="form-control form-control-border" id="alamat"><?=$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" id="kabupaten"><?=$data->nama_kabupaten?></span>
                                                                </div>
                                                                <div class="form-group">
                                                                    <label for="kecamatan">Kecamatan</label>
                                                                    <span class="form-control form-control-border" id="kecamatan"><?=$data->nama_kecamatan?></span>
                                                                </div>
                                                                <div class="form-group">
                                                                    <label for="kelurahan">Kelurahan</label>
                                                                    <span class="form-control form-control-border" id="kelurahan"><?=$data->nama_kelurahan?></span>
                                                                </div>
                                                                <div class="form-group">
                                                                    <label for="lat">Latitude</label>
                                                                    <span class="form-control form-control-border" id="lat"><?=$data->lat?></span>
                                                                </div>
                                                                <div class="form-group">
                                                                    <label for="lng">Longitude</label>
                                                                    <span class="form-control form-control-border" id="lng"><?=$data->lng?></span>
                                                                </div>
                                                                <div class="form-group">
                                                                    <div id="map" class="map">
                                                                    </div>
                                                                </div>
                                                            </form>
                                                        </div>
                                                        <div class="card-footer text-right">
                                                            
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="tab-pane text-left fade" id="vert-tabs-dokumen" role="tabpanel" aria-labelledby="vert-tabs-dokumen-tab">
                                            <div class="card card-outline card-info">
                                                <div class="card-header">
                                                    <div class="card-title">
                                                        Dokumen
                                                    </div>
                                                </div>
                                                <div class="card-body">
                                                    <div class="card">
                                                        <div class="card-body d-flex">
                                                            <div class="ml-2">
                                                                <p>
                                                                    <b>KTP</b><br>
                                                                    <?php
                                                                        $status1 = false;
                                                                        if (!empty($data->ktp))
                                                                        {
                                                                            $status1=true;
                                                                            ?>
                                                                            <img class="img-fluid" src="<?=base_url()?>uploads/agen/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>SK</b><br>
                                                                    <?php
                                                                        $status2 = false;
                                                                        if (!empty($data->sk))
                                                                        {
                                                                            $status2=true;
                                                                            echo 'File : '.$data->sk;
                                                                        }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->sk?>','sk');">
                                                                        <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>Kontrak Pangkalan</b><br>
                                                                    <?php
                                                                        $status3 = false;
                                                                        if (!empty($data->kontrak_pangkalan))
                                                                        {
                                                                            $status3=true;
                                                                            echo 'File : '.$data->kontrak_pangkalan;
                                                                        }else{
                                                                            echo 'No File Available';
                                                                        }
                                                                    ?>
                                                                </p>
                                                            </div>
                                                            <div class="ml-auto">
                                                                <?php
                                                                if (!$status3){
                                                                ?>
                                                                
                                                                <?php
                                                                }else{
                                                                    ?>
                                                                    
                                                                    <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->kontrak_pangkalan?>','kontrak_pangkalan');">
                                                                        <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 Lokasi</b><br>
                                                                    <?php
                                                                        $status4 = false;
                                                                        if (!empty($data->foto_lokasi))
                                                                        {
                                                                            $status4=true;
                                                                            ?>
                                                                            <img class="img-fluid" src="<?=base_url()?>uploads/agen/dokumen/foto_lokasi/<?=$data->foto_lokasi?>">
                                                                            <?php
                                                                        }else{
                                                                            echo 'No File Available';
                                                                        }
                                                                    ?>
                                                                </p>
                                                            </div>
                                                            <div class="ml-auto">
                                                                <?php
                                                                if (!$status4){
                                                                ?>
                                                                
                                                                <?php
                                                                }else{
                                                                    ?>
                                                                    
                                                                    <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->foto_lokasi?>','foto_lokasi');">
                                                                        <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
                                                                        $status5 = false;
                                                                        if (!empty($data->foto_selfie_ktp))
                                                                        {
                                                                            $status5=true;
                                                                            ?>
                                                                            <img class="img-fluid" src="<?=base_url()?>uploads/agen/dokumen/foto_selfie_ktp/<?=$data->foto_selfie_ktp?>">
                                                                            <?php
                                                                        }else{
                                                                            echo 'No File Available';
                                                                        }
                                                                    ?>
                                                                </p>
                                                            </div>
                                                            <div class="ml-auto">
                                                                <?php
                                                                if (!$status5){
                                                                ?>
                                                                
                                                                <?php
                                                                }else{
                                                                    ?>
                                                                    
                                                                    <a class="btn btn-app bg-success" href="javascript:download_file('<?=$data->foto_selfie_ktp?>','foto_selfie_ktp');">
                                                                        <i class="fas fa-download"></i> Download
                                                                    </a>
                                                                    <?php
                                                                }
                                                                ?>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </section>
    <style>
        .map {
            width: 100%;
            height: 500px;
        }
    </style>
    
    <script>
        function download_file(filename,target)
        {
            var link = document.createElement('a');
            link.download = filename;
            link.href ="<?=base_url()?>/uploads/agen/dokumen/"+target+"/"+filename;  
            link.click();
        }
    </script>
    
    <script>
        var map;
        var map2;
        var markers = [];
        var markers2 = [];
        var iconBase;
        var icons;
        $(document).ready(function () {
            const infoWindow = new google.maps.InfoWindow();
            function initMap() {
                map = new google.maps.Map(document.getElementById("map"), {
                    zoom: 12,
                    center: { lat: 3.6424551, lng: 98.5994535 },
                });

                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>