@extends('layouts.master')

@section('title', 'List User')
@section('content')
<!-- Start content -->
<div class="content">
    <div class="container-fluid">
      <div class="row">
            <div class="col-12">
                <div class="card-box table-responsive">
                    <h4 class="m-t-0 m-b-20 header-title"><b>List User <span class="label label-danger">EXPIRED</span></b></h4>
                    <table id="datatable-buttons" class="table table-striped table-bordered" cellspacing="0" width="100%">
                        <colgroup>
                          <col style="width:10%"/>
                          <col style="width:10%"/>
                          <col style="width:13%"/>
                          <col style="width:14%"/>
                          <col style="width:6%"/>
                          <col style="width:17%"/>
                          <col style="width:15%"/>
                          @if (auth()->user()->level == 'admin')
                          <col style="width:15%"/>
                          @endif
                        </colgroup>
                        <thead>
                        <tr>
                            <th>Username</th>
                            <th>Level</th>
                            <th>Registered By</th>
                            <th>Expired</th>
                            <th>Status</th>
                            <th>Saldo</th>
                            <th>Registered At</th>
                            @if (auth()->user()->level == 'admin')
                            <th>Action</th>
                            @endif
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <!-- container -->

</div>
<!-- content -->
@endsection

@section('js')
<script type="text/javascript">
var resizefunc = [];
var table;
$(document).ready(function() {
    table = $('#datatable-buttons').DataTable({
    serverSide: true,
    processing: true,
    order: [[ 3, "desc" ]],
    ajax: '{{ route('users.expired.list') }}',
    columns: [
        {data: 'username'},
        {data: 'level'},
        {data: 'register_by'},
        {data: 'expired_date'},
        {data: 'status'},
        {data: 'saldo'},
        {data: 'created_at'},
        @if (auth()->user()->level == 'admin')
        {data: 'action'}
        @endif
    ]
    });
});



    function suspend(id){
        var popup = confirm("Are you sure?");
        if(popup){
            $.ajax({
                url: "{{ url('/user/suspend') }}"+ '/' +id,
                type: "GET",
                success: function(data){
                    table.ajax.reload();
                },
                error: function(){
                    alert('Something wrong');
                }
            });
        }
    }


</script>
@endsection
