<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">Notifikasi Pengajuan 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 active">Data Notifikasi 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 Notifikasi Pengajuan Pangkalan
                            </div>
                        </div>
                        <div class="card-body">
                            <table id="tbl_data1" class="table table-striped table-bordered display compact nowrap" style="width:100%">
                                <thead>
                                    <tr>
                                        <th class="not-export">Status</th>
                                        <th class="sb-filter">Tipe</th>
                                        <th class="sb-filter">Tanggal</th>
                                        <th class="sb-filter">ID Registrasi</th>
                                        <th class="sb-filter">Nama Pangkalan</th>
                                        <th class="sb-filter">Pesan</th>
                                    </tr>
                                </thead>
                                <tbody>

                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="row">
                <div class="col-lg-12">
                    <div class="card card-outline card-primary">
                        <div class="card-header">
                            <div class="card-title">
                                Daftar Notifikasi Pengajuan Perubahan Pangkalan
                            </div>
                        </div>
                        <div class="card-body">
                            <table id="tbl_data2" class="table table-striped table-bordered display compact nowrap" style="width:100%">
                                <thead>
                                    <tr>
                                        <th class="not-export">Status</th>
                                        <th class="sb-filter">Tipe</th>
                                        <th class="sb-filter">Tanggal</th>
                                        <th class="sb-filter">ID Registrasi</th>
                                        <th class="sb-filter">Nama Pangkalan</th>
                                        <th class="sb-filter">Pesan</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, 'desc']],
                    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',0]
                    },
                    language : {
                        searchBuilder: {
                            button: '<span class="fas fa-search"> Filter</span>',
                        }
                    },
                    ajax: {
                        url : '<?=base_url()?>get_admin_notifikasi_pengajuan',
                        type : 'POST'
                    },
                    columns: [
                        { data: 'dilihat',
                            searchable : false,
                            orderable : true },
                        { data: 'tipe' },
                        { data: 'tanggal' },
                        { data: 'id_registrasi' },
                        { data: 'nama_pangkalan' },
                        { data: 'pesan' },
                    ],
                    "createdRow": function( row, data, dataIndex){
                        if( data['tipe'] ==  "revision"){
                            $(row).addClass('bg-warning');
                        }else if( data['tipe'] ==  "reject"){
                            $(row).addClass('bg-danger');
                        }else if( data['tipe'] ==  "approve"){
                            $(row).addClass('bg-success');
                        }
                    },
                    columnDefs: [
                        {
                            targets:0,
                            "render": function ( data, type, row, meta ) {
                                if (type === 'display')
                                {
                                    if (row.dilihat == "0")
                                    {
                                        return '<button id="set_dilihat" class="btn btn-sm bg-gradient-info btn-view">Tandai Telah Dilihat</button>';
                                    }else{
                                        return '<span class="btn btn-sm bg-gradient-success">Telah Dilihat</span>';
                                    }
                                }else if (type === 'type')
                                {
                                    return data;
                                }else if (type === 'sort')
                                {
                                    return data;
                                }
                            }
                        }
                    ],
                    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();
                    var id = data['id_notif_admin_pengajuan_pangkalan'];

                    Swal.fire({
                        title:'Processing..',
                        html:'<p>Please wait..</p>',
                        allowOutsideClick:false
                    });
                    Swal.showLoading();
                    $.post("<?=base_url()?>admin_notif_pengajuan_dilihat",{id_notifikasi:id}).done(function (data) {
                        Swal.fire({
                            text:'Notifikasi berhasil ditandai!',
                            icon : 'success'
                        }).then(function () {
                            window.location.href = '<?=base_url()?>admin_notifikasi_pengajuan';
                        });
                    }).fail(function (data) {
                        Swal.fire({
                            text:'Terjadi kesalahan pada saat penyimpanan!',
                            icon : 'error'
                        });
                    });
                });

                var table2 = $("#tbl_data2").DataTable({
                    processing: true,
                    serverSide: true,
                    scrollX: true,
                    pageLength:25,
                    searchDelay: 1500,
                    order: [[1, 'desc']],
                    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',0]
                    },
                    language : {
                        searchBuilder: {
                            button: '<span class="fas fa-search"> Filter</span>',
                        }
                    },
                    ajax: {
                        url : '<?=base_url()?>get_admin_notifikasi_perubahan',
                        type : 'POST'
                    },
                    columns: [
                        { data: 'dilihat',
                            searchable : false,
                            orderable : true },
                        { data: 'tipe' },
                        { data: 'tanggal' },
                        { data: 'id_registrasi' },
                        { data: 'nama_pangkalan' },
                        { data: 'pesan' },
                    ],
                    "createdRow": function( row, data, dataIndex){
                        if( data['tipe'] ==  "revision"){
                            $(row).addClass('bg-warning');
                        }else if( data['tipe'] ==  "reject"){
                            $(row).addClass('bg-danger');
                        }else if( data['tipe'] ==  "approve"){
                            $(row).addClass('bg-success');
                        }
                    },
                    columnDefs: [
                        {
                            targets:0,
                            "render": function ( data, type, row, meta ) {
                                if (type === 'display')
                                {
                                    if (row.dilihat == "0")
                                    {
                                        return '<button id="set_dilihat" class="btn btn-sm bg-gradient-info btn-view2">Tandai Telah Dilihat</button>';
                                    }else{
                                        return '<span class="btn btn-sm bg-gradient-success">Telah Dilihat</span>';
                                    }
                                }else if (type === 'type')
                                {
                                    return data;
                                }else if (type === 'sort')
                                {
                                    return data;
                                }
                            }
                        }
                    ],
                    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_data2 tbody').on('click','.btn-view2',function () {
                    var data = table2.row($(this).parents('tr')[0]).data();
                    var id = data['id_notif_admin_pengajuan_perubahan'];

                    Swal.fire({
                        title:'Processing..',
                        html:'<p>Please wait..</p>',
                        allowOutsideClick:false
                    });
                    Swal.showLoading();
                    $.post("<?=base_url()?>admin_notif_perubahan_dilihat",{id_notifikasi:id}).done(function (data) {
                        Swal.fire({
                            text:'Notifikasi berhasil ditandai!',
                            icon : 'success'
                        }).then(function () {
                            window.location.href = '<?=base_url()?>admin_notifikasi_pengajuan';
                        });
                    }).fail(function (data) {
                        Swal.fire({
                            text:'Terjadi kesalahan pada saat penyimpanan!',
                            icon : 'error'
                        });
                    });
                });
            });
        </script>

    </section>
</div>