@extends('layouts.app')
@section('title','List of Users | ')
@section('content')
<!-- Content Header (Page header) -->
<div class="content-header">
    <div class="container-fluid">
        <div class="row mb-2">
            <div class="col-sm-6">
                <h1 class="m-0">All Users</h1>
            </div><!-- /.col -->
            <div class="col-sm-6">
                <ol class="breadcrumb float-sm-right">
                    <li class="breadcrumb-item"><a href="#">Home</a></li>
                    <li class="breadcrumb-item active">All Users</li>
                </ol>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
<!-- Main content -->
<section class="content">
    <div class="container-fluid">
        <div class="card">
            <div class="card-header">
                <h3 class="card-title">List of all users</h3>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
            @if(session('success'))
                    <div class="alert alert-success alert-dismissible fade show" role="alert">
                        <strong>{{ session('success') }}</strong>
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                @endif
                @if(session('error'))
                    <div class="alert alert-danger alert-dismissible fade show" role="alert">
                        <strong>{{ session('error') }}</strong>
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                @endif
                @if(session('warning'))
                    <div class="alert alert-warning alert-dismissible fade show" role="alert">
                        <strong>{{ session('warning') }}</strong>
                        <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                @endif
            @if(Auth::user()->user_role == 1 || Auth::user()->user_role == 2 || Auth::user()->user_role == 3)
                <table id="EmployeeList" class="table table-bordered table-striped">
                    <thead>
                        <tr>
                            <th>Sr No.</th>
                            <th>Full Name</th>
                            <th>Email</th>
                            <th>Mobile</th>
                            <th>User Role</th>
                            <th>District</th>
                            <th>Emp Status</th>
                            <th>Action</th>
                        </tr>
                    </thead>
                    <tbody>
                    @if($users->count() > 0)
                            @php
                                $count = 1;
                            @endphp
                            @foreach($users as $user)
                                <tr class="{{ ($user->emp_status == 0) ? 'bg-danger' :'' }}">
                                    <td>{{ $count }}</td>
                                    <td>{{ $user->full_name }}</td>
                                    <td>{{ $user->email }}</td>
                                    <td>{{ $user->mobile_number }}</td>
                                    <td>
                                        @if($user->user_role == 1)
                                            {{ __('Super Admin') }}
                                        @elseif($user->user_role == 2)
                                            {{ __('Admin/HR') }}
                                        @elseif($user->user_role == 3)
                                            {{ __('Team Lead') }}
                                        @elseif($user->user_role == 4)
                                            {{ __('Employee') }}
                                        @endif
                                    </td>
                                    <td>
                                        {{ $user->district_name }}
                                    </td>
                                    <td>
                                        @if($user->emp_status == 1)
                                            {{ __('Active') }}
                                        @elseif($user->emp_status == 0)
                                            {{ __('Inactive') }}
                                        @endif
                                    </td>
                                    <td>
                                        <a href="{{ route('edit.employee',$user->id) }}" class="p-1 mr-2 "><i class="fa fa-edit  text-warning"></i></a>
                                        @if($user->emp_status == 1)
                                        <a href="#" class="p-1 deactivate-employee mr-1" data-id="{{ route('deactivate.employee', $user->id) }}"><i class="fa fa-trash  text-danger"></i></a>
                                        @endif
                                        <a href="#" data-id="{{ $user->id }}" class="btn btn-sm btn-success reset-user-password">Reset Password</a>
                                    </td>
                                </tr>
                                @php
                                $count++; 
                                @endphp
                                @endforeach
                            @endif
                    </tbody>
                </table>
            @else 
                <p class="text-info">Permission denied: You don't have access permission to access this page</p>
            @endif
            </div>
            <!-- /.card-body -->
        </div>
        <!-- /.card -->
    </div>
    <!--/. container-fluid -->
</section>
<!-- /.content -->
@stop
