<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 Pengajuan Pangkalan Baru</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">Data Pengajuan Pangkalan</li>
                    </ol>
                </div><!-- /.col -->
            </div><!-- /.row -->
        </div><!-- /.container-fluid -->
    </div>
    <hr/>
    <section class="content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">
                    <div class="card card-outline card-primary">
                        <div class="card-header">
                            <div class="card-title">
                                Daftar Data Pengajuan Pangkalan Baru
                            </div>
                            <div class="card-tools">
                                <a href="<?=base_url()?>agen_pangkalan_pengajuan_add" class="btn btn-sm btn-primary">Tambah Pengajuan Baru</a>
                            </div>
                        </div>
                        <div class="card-body">
                            <table id="tbl_data1" class="table table-striped table-bordered display compact cell-border row-border nowrap" style="width:100%">
                                <thead>
                                    <tr>
                                        <th class="not-export">Action</th>
                                        <th class="sb-filter">Status</th>
                                        <th class="sb-filter">Tipe Pangkalan</th>
                                        <th class="sb-filter">ID Registrasi</th>
                                        <th class="sb-filter">Nama Pangkalan</th>
                                        <th class="sb-filter">No. Telepon</th>
                                        <th class="sb-filter">Nama Pemilik</th>
                                        <th class="sb-filter">No. KTP Pemilik</th>
                                        <th class="sb-filter">No. HP Pemilik</th>
                                        <th class="sb-filter">Kuantiti</th>
                                        <th class="sb-filter">Provinsi</th>
                                        <th class="sb-filter">Kabupaten</th>
                                        <th class="sb-filter">Kecamatan</th>
                                        <th class="sb-filter">Kelurahan</th>
                                    </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            
        </div>
        <style>
            .dataTables_wrapper .dataTables_filter{
                float:left !important;
            }
        </style>
        <script type="text/javascript">
            $(document).ready(function () {
                <?php
                if (isset($error))
                {
                    ?>
                    $(document).Toasts('create', {
                        class: 'bg-danger',
                        title: 'Error',
                        subtitle: 'Terjadi Kesalahan',
                        body: '<?=$error?>'
                    })
                    <?php
                }
                ?>
                var table1 = $("#tbl_data1").DataTable({
                    processing: true,
                    serverSide: true,
                    scrollX: true,
                    pageLength:25,
                    searchDelay: 1500,
                    order: [[1, 'asc']],
                    dom: "<'row mb-3'<'col-sm-12'Q>>" +
                    "<'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>>",
                    searchBuilder: {
                        columns: ['.sb-filter']
                    },
                    language : {
                        searchBuilder: {
                            button: '<span class="fas fa-search"> Filter</span>',
                        }
                    },
                    ajax: {
                        url : '<?=base_url()?>get_agen_pangkalan_pengajuan',
                        type : 'POST'
                    },
                    columns: [
                        { data: null,
                            searchable : false,
                            orderable : false },
                        { data: 'status' },
                        { data: 'nama_tipe' },
                        { data: 'id_registrasi' },
                        { data: 'nama_pangkalan' },
                        { data: 'no_telepon' },
                        { data: 'nama_pemilik' },
                        { data: 'no_ktp_pemilik' },
                        { data: 'no_hp_pemilik' },
                        { data: 'kuantiti' },
                        { data: 'nama_provinsi' },
                        { data: 'nama_kabupaten' },
                        { data: 'nama_kecamatan' },
                        { data: 'nama_kelurahan' },
                    ],
                    columnDefs: [
                        {
                            targets:1,
                            "render": function ( data, type, row, meta ) {
                                if (type === 'display')
                                {
                                    if (data == 'draft')
                                    {
                                        return '<div class="btn bg-gradient-secondary btn-block btn-sm">Draft</div>';
                                    }else if (data == 'waiting')
                                    {
                                        return '<div class="btn bg-gradient-info btn-block btn-sm">Waiting</div>';
                                    }else if (data == 'revision')
                                    {
                                        return '<div class="btn bg-gradient-warning btn-block btn-sm">Revision</div>';
                                    }else if (data == 'reject')
                                    {
                                        return '<div class="btn bg-gradient-danger btn-block btn-sm">Reject</div>';
                                    }else if ((data == 'approve') || (data == 'AKTIF'))
                                    {
                                        return '<div class="btn bg-gradient-success btn-block btn-sm">Approved / Aktif</div>';
                                    }
                                }else if (type === 'type')
                                {
                                    return data;
                                }else if (type === 'sort')
                                {
                                    return data;
                                }
                            }
                        },
                        {
                            targets: 0,
                            data: null,
                            defaultContent: '<button class="btn-view btn btn-block bg-gradient-success btn-sm"><span class="fas fa-search"></span> View</button>',
                        },
                    ],
                    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)' ]
                            }
                        }
                    ],
                    "initComplete": function(settings, json) {
                    }
                });

                $('#tbl_data1 tbody').on('click','.btn-view',function () {
                    var data = table1.row($(this).parents('tr')[0]).data();
                    document.location.href='<?=base_url()?>agen_view_pangkalan_add/'+data['id_pangkalan'];
                });
            });
        </script>

    </section>
</div>