@extends('layout')
@section('title','Liste des utilisateurs ')
@section('content')


<div class="section-header">
            <h1>Liste des utilisateurs</h1>
            <div class="section-header-breadcrumb">
              <div class="breadcrumb-item active"><a href="{{route('Register')}}">Utilisateurs</a></div>
              <div class="breadcrumb-item"><a href="#">Liste utilisateurs</a></div>
            </div>
          </div>
        
		  
		  
		  <div class="section-body">
		     @if (session('status'))
            <div class="alert alert-warning" style="font-size: 15px; background-color: #328039; color: white">
                <i class="fa fa-check"></i> &nbsp; {{ session('status') }}
            </div>
        @endif

        @if (session('error'))
            <div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white">
                <i class="ti-na"></i> {{ session('error') }}
            </div>
        @endif
        @if ($errors->any())
            <div class="alert alert-danger" style="font-size: 15px; background-color: #fb5757; color: white" >
                <ul>
                    @foreach ($errors->all() as $error)
                        <li> <i class="ti-na"></i> {{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif
            <div class="row">
              <div class="col-12">
                <div class="card">
                  <div class="card-header">
                    <h4></h4>
                  </div>
                  <div class="card-body">
                    <div class="table-responsive">
                      <table class="table table-striped" id="table-1">
                        <thead>
                          <tr>
                            <th class="text-center"> N° </th>
                            <th class="text-center">Nom & Prénom(s)</th>
                            <th class="text-center">Login</th>
                            <th class="text-center">Rôle</th>
                            <th class="text-center">Dépôt</th>
					         <th>Action</th>
                          </tr>
                        </thead>
                        <tbody>
						@foreach($user as $users)
                          <tr>
                            <td class="text-center">{{$loop->iteration}}</td>
                            <td class="text-center"> {{ $users->nom }}</td>
							<td class="text-center"> {{$users->login}}</td>
							<td class="text-center"> {{$users->roles}}</td>
							<td class="text-center"> {{DB::table('magasin')->where('id',$users->magasin_id)->first()->nom}}</td>
							<td>
							<a type="button" href="{{route('modification',['id'=>$users->id])}}" data-toggle="tooltip" data-placement="bottom" title="Modifier" class="btn btn-icon btn-info"><i class="fas fa-edit"></i></a>
							<a type="button" href="#" data-id="{{$users->id}}" data-toggle="tooltip" data-placement="bottom" title="Supprimer" class="btn btn-icon btn-danger data-supprimer"><i class="fas fa-trash"></i></a>
							</td>
                          </tr>
						@endforeach
                        </tbody>
                      </table>
                    </div>
                  </div>
                </div>
              </div>
            </div>
           
           
          </div>
		  
		 </div>
          </div>
		  
		    <div class="modal fade" id="Supprimermodal" >
          <div class="modal-dialog" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Suppression </h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                  <span aria-hidden="true">&times;</span>
                </button>
              </div>
              <div class="modal-body">
                Voulez-vous vraiment supprimer cet utilisateur ?
              </div>
              <div class="modal-footer bg-whitesmoke br" style="background-color:#ffffff" id="delete">
                
              </div>
            </div>
          </div>
        </div>
		  
@push('scripts') 
	   
	  <script>
        $(".data-supprimer").on('click', function () {
                var id=$(this).data('id');
                $.get(location.origin+'/es/Users/'+id, function (data) {
                  var html = `
            <button type="button" class=" btn btn-danger" data-dismiss="modal">Non</button>
                      <form action="{{route('SupprimerUserPost')}}" method="post" style="display: inline">
                        {{csrf_field()}}
                      <input type="hidden" value="`+data.user.id+`" name="id" >
                      <button type="submit" class="btn btn-success">Oui</button>

            </form>`
            ;
            $('#delete').html('').append(html);
          })
          $('#Supprimermodal').modal();
        });
    </script>
	 
@endpush

@endsection