@extends('backend._partials.app')
@section('maincontent')

    <div class="col-md-12">
        <div class="card">
            <div class="header">
                <h4 class="title" style="display: inline;">Users list</h4>
                <button data-toggle="modal" data-target="#modal" onclick="loadModal('user/create')" class="btn btn-info btn-fill pull-right">NEW USER <i class="fa fa-plus" aria-hidden="true"></i> </button>
            </div>
            <div class="content">
                <div class="fresh-datatables">
                    <table id="datatable" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
                        <thead>
                        <tr>
                            <th>Image</th>
                            <th>Name</th>
                            <th>Designation</th>
                            <th>Email</th>
                            <th>Mobile No</th>
                            <th>Timezone</th>
                            <th>Last Login</th>
                            <th>Status</th>
                            <th>Action</th>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($users as $user)
                            <tr>
                                <td>@if(empty($user->image))
                                        <img src="{{asset("public/img/users/default-avatar.png")}}" height="40">
                                    @else
                                        <img src="{{asset("public/img/users/$user->image")}}" height="40">
                                    @endif
                                </td>
                                <td>{{$user->first_name. " ".$user->last_name}}</td>
                                <td>{{@$user->designation->title}}</td>
                                <td>{{$user->email}}</td>
                                <td>{{$user->mobile_no}}</td>
                                <td>{{$user->timezone}}</td>
                                <td>{{$user->last_login_time}}</td>
                                <td>
                                    @if($user->status==1)
                                        <label class="label label-success">Active</label>
                                    @else
                                        <label class="label label-warning">Inactive</label>
                                    @endif
                                </td>
                                <td class="text-right">
                                    <a title="User Report" href="{{URL::to('user-details-report')}}/{{$user->id}}" class="btn btn-simple btn-info btn-icon"><i class="fa fa-file-o"></i></a>
                                    <a class="btn btn-simple btn-warning btn-icon" data-toggle="modal" data-target="#modal" onclick="loadModalEdit('user',{{$user->id}},'edit')" title="User Details"><i class="fa fa-edit"></i></a>
                                        <a class="btn btn-simple btn-danger btn-icon remove" @if(Auth::id()!=$user->id) onclick="deleteConfirm('userDelete',{{$user->id}})" title ="User Delete" @else disabled="" rel="tooltip" title="You can't delete yourself." @endif><i class="fa fa-times"></i></a>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    <script type="text/javascript">

        function deleteConfirm(url,id) {

            swal({
                title: "Are you sure?",
                text: "You will not be able to recover this!",
                type: "warning",
                showCancelButton: true,
                closeOnConfirm: true,
                closeOnCancel: true
            }, function (isConfirm) {
                if (isConfirm) {
                    window.location='{{URL::to('/')}}/'+url+"/"+id;
                    //swal("Deleted!", "Your imaginary file has been deleted.", "success");
                }
            });
        }

    </script>
    @include('backend._partials.ajax')
@endsection