@extends('layouts.master')

@section('title')
    Dashboard
@endsection

@section('header')
<div class="page-title">
    <h3>Dashboard</h3>
</div>
@endsection

@section('contents')
    <!-- start page title -->
    <div class="page-title-box">
        <div class="row align-items-center">
            <div class="col-md-8">
                <h6 class="page-title">{!! $title !!}</h6>
                <ol class="breadcrumb m-0">
                    <li class="breadcrumb-item">{!! $title !!}</li>
                </ol>
            </div>
        </div>
    </div>
    <!-- end page title -->



    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <table id="example" class="table table-bordered dt-responsive nowrap" style="border-collapse: collapse; border-spacing: 0; width: 100%;">

                        <thead>
                            <tr>
                                <th>No</th>
                                <th>Kode Kelompok</th>
                                <th>Ketua</th>
                                <th>NIM</th>
                                <th>Dosen Pembimbing</th>
                                <th>NIDN</th>
                                <th>Status</th>
                                <th>Aksi</th>
                            </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>

                </div>
            </div>
        </div> <!-- end col -->
    </div> <!-- end row -->

    <div class="modal fade" id="empModal">
        <div class="modal-dialog modal-xl">
            <div class="modal-content">
                <div class="modal-header">
                    <h4 class="modal-title">Data Kelompok</h4>
                    <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
                </div>
                <div class="modal-body">
                    <table class="w-100" id="tblempinfo">
                        <thead>
                            <tr>
                                <th>No</th>
                                <th>Nama</th>
                                <th>NIM</th>
                                <th>Fakultas</th>
                                <th>Program Studi</th>
                                <th>Keterangan</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-danger" data-bs-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
@endsection

@section('js')
<script>
    $(document).ready(function(){
        // DataTable
        var oTable = $('#example').DataTable({
            processing: true,
            serverSide: true,
            ajax: {
                "url" : "{{route('operator.getKelompok')}}"
            },
            columns: [
                { data: 'kelompok_id' },
                { data: 'kode' },
                { data: 'nama_ketua' },
                { data: 'nim_ketua' },
                { data: 'nama_dosen' },
                { data: 'nidn_dosen' },
                { data: 'keterangan' },
                { data: 'aksi' },
            ],
            columnDefs: [
            {
                "targets": [ 0 ],
                "visible": false,
                "searchable": false
            }
        ]
        });
    });

    $(document).ready(function(){

        $('#example').on('click','.viewdetails',function(){
            var kelId = $(this).attr('data-id');


        if(kelId != null || kelId != ''){
                // Empty modal data
                $('#tblempinfo tbody').empty();

                $.ajax({
                    url: "{{route('operator.getDetilKelompok')}}",
                    data : {
                        "kelompok_id": kelId,
                    },
                    dataType: 'json',
                    success: function(response){
                        // Add user details
                        $('#tblempinfo tbody').html(response.html);

                        // Display Modal
                        $('#empModal').modal('show');
                    }
                });
        }
        });

    });
</script>
@endsection
