<x-app-layout>
    {{-- <x-slot name="header">
        <h2 class="font-semibold text-xl text-gray-800 leading-tight">
            {{ __('Dashboard') }}
        </h2>
    </x-slot> --}}


    <div class="py-4">
        <div class="container-fluid">
            @if (session()->has('message'))
                <div class="alert alert-icon-right alert-success alert-dismissible mt-2" role="alert">
                    <span class="alert-icon">
                        <i class="la la-info"></i>
                    </span>
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                        <span aria-hidden="true">×</span>
                    </button>
                    <strong>{{ session('message') }}</strong>
                </div>
            @endif
            <div class="app-content content">
                <div class="details-wrapper">
                    <div class="content-body">
                        <section id="configuration">
                            <div class="row">
                            <div class="col-12">
                            <nav aria-label="breadcrumb ">
                          <ol class="breadcrumb bg-white">
                            <li class="breadcrumb-item"><a href="{{ url('quicklinks/list/Published') }}">Quick Links</a></li>
                            <li class="breadcrumb-item"><a href="{{ url('quicklinkcategories/list/Active') }}">Categories</a></li>
                            <li class="breadcrumb-item active" aria-current="page">Listing</li>
                          </ol>
                        </nav>
                        </div></div>
                            <div class="row">
                                <div class="col-12">
                                    <div class="card">
                                        <div class="card-header">
                                            <h4 class="card-title">Categories</h4>
                                            <div class="pageSort">
                                                <a class="btn btn-outline-primary @if($status == 'Active') active @endif" href="{{url('quicklinkcategories/list/Active')}}">Active @if(isset($activecategoriesCount) && $activecategoriesCount!=0)({{$activecategoriesCount}})@endif</a>
                                                <a class="btn btn-outline-primary @if($status == 'Inactive') active @endif" href="{{url('quicklinkcategories/list/Inactive')}}">Inactive @if(isset($inactivecategoriesCount) && $inactivecategoriesCount!=0)({{$inactivecategoriesCount}})@endif</a>
                                                @if(Auth::user()->role_id != '3')
                                                    <a class="btn btn-outline-primary" href="{{ route('quicklinkcategories.create') }}">Create</a>
                                                @endif    
                                        </div>
                                        </div>
                                        <div class="card-content collapse show">
                                            <div class="card-body card-dashboard">
                                                <div class="table-responsive">
                                                    <table class="table yajra-datatable">
                                                        <thead>
                                                            <tr>
                                                            <th class="slNo">Sl No.</th>
                                                                <th>Category Name</th>
                                                                @if(Auth::user()->role_id != '3')
                                                                <th class="text-right">Action</th>
                                                                @endif
                                                            </tr>
                                                        </thead>
                                                    </table>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </section>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script type="text/javascript" src="{{ asset('js/datatables.min.js') }}"></script>
    <script type="text/javascript" src="{{ asset('js/datatable-basic.js') }}"></script>
    <script type="text/javascript">
        $(function () {
            
            var table = $('.yajra-datatable').DataTable({
                autoWidth: false,
                processing: true,
                serverSide: true,
                ajax: "{{ route('quicklinkcategories.list',$status) }}",
                columns: [
                    {data: 'DT_RowIndex', name: 'DT_RowIndex'},
                    {data: 'categoryname', name: 'categoryname'},
                    <?php if( Auth::user()->role_id != '3') { ?>
                    {
                        data: 'action', 
                        name: 'action', 
                        orderable: true, 
                        searchable: true,
                        class:'text-right'
                    },
                    <?php } ?>
                ]
            });
            
        });
        $(document).ready(function(){
            if( $(".alert-dismissible").length > 0 ){
                setTimeout(function(){
                    $(".alert-dismissible").fadeOut('slow');
                },3000);
            }
        });

        function showQuicklinkCategoryDeleteModal(id)
        {
            swal({
                title: "Are you sure you want to delete this category?",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonClass: "btn-danger",
                confirmButtonText: "OK",
                closeOnConfirm: true,
                showLoaderOnConfirm: false
          },
          function(){
           $.ajax({
                type: "DELETE",
                url: "{{ URL::to('/quicklinkcategories/destroy')}}",
                data: 
                {'id':id,'status':'delete',"_token": "{{ csrf_token() }}"},
                dataType : 'json',
                success: function(data) {
                    if(data.success==1)
                    {
                      
                        swal("Category deleted successfully",'','success');
                        window.location.reload();
                    }
                    

                    }
                });
             });
        }
        function activateCategory(id){
            swal({
                title: "Are you sure you want to activate this category?",
                text: "",
                type: "warning",
                showCancelButton: true,
                confirmButtonClass: "btn-danger",
                confirmButtonText: "OK",
                closeOnConfirm: true,
                showLoaderOnConfirm: false
          },
          function(){
            $.ajax({
                type: "POST",
                url: "{{ URL::to('quicklinkcategories/activate/{id}')}}",
                data: 
                {'id':id,"_token": "{{ csrf_token() }}"},
                dataType : 'json',
                success: function(data) {
                    if(data.success==1)
                    {
                        swal("Category activated successfully",'','success');
                        window.location.reload();
                    }

                    }
                     });
        });
        } 
    </script>
</x-app-layout>