@extends('layouts.app')

@section('content')
<div class="container mt-3">
    <div class="row justify-content-center">
      <div class="col-md-12 col-lg-12 col-sm-12">
        <a href="{{route('user.create')}}" ><button type="button" class="btn btn-primary">Add User</button></a>
        @if (session('success'))
          <div class="alert alert-success mt-3">
              {!! session('success') !!}
          </div>
        @endif
       <div class="table-responsive">
            <table class="table table-sm table-hover mt-3">
              <thead class="thead-light">
                <tr>
                  <th class="text-left px-3" >Id</th>
                  <th class="text-left px-3" >Name</th>
                  <th class="text-left px-3" >Email</th>
                  <th class="text-left px-3" >Role</th>
                  <th class="text-right px-3" >Action</th>
                </tr>
              </thead>
              <tbody>
              @foreach($users as $user)
                <tr class="text-left">
                  <td class="p-3" style="vertical-align: middle;"> {{$user->id}}</td>
                  <td class="p-3" style="vertical-align: middle;">{{$user->name}}</td>
                  <td class="p-3" style="vertical-align: middle;">{{$user->email}}</td>
                  <td class="p-3" style="vertical-align: middle;">{{$user->type}}</td>
                  
                  <td class="d-flex flex-row justify-content-end p-3"> 
                    <a href="{{route('user.edit',$user->id)}}"class="button_design"><button type="button" class="btn btn-success mb-1 btn-sm">EDIT</button></a>&nbsp;&nbsp;
                    <form action="{{route('user.destroy',$user->id)}}" method="post">
                      @csrf
                      @method('delete')
                      <button type="submit" class="btn btn-danger btn-sm" data-original-title="" title="" onclick="confirm('{{ __("Are you sure you want to delete this user?") }}') ? this.parentElement.submit() : ''">DELETE</button>&nbsp;&nbsp;
                    </form>
                    <a href="/user/{{$user->id}}/object"><button type="button" class="btn btn-primary btn-sm">ASSIGN OBJECT</button></a>
                  </td>
                </tr>
                @endforeach 
              </tbody>
            </table>
        </div>  

        <div class="d-flex justify-content-center">
        {{ $users->links('user.pagination')  }}
        </div>
      </div>
    </div>
</div>



@endsection
