@extends('Templates/templateAdmin')

@section('Main-content')
    <section class="content">

        <div class="container-fluid">
            @if (session('success'))
                <div class="alert alert-success">
                    {{ session('success') }}
                </div>
            @endif
            <br>
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">Tabela Utilizadores</h3>

                    <div class="card-tools">
                        <div class="input-group input-group-sm" style="width: 150px;">
                            <input type="text" name="table_search" class="form-control float-right" placeholder="Search">

                            <div class="input-group-append">
                                <button type="submit" class="btn btn-default">
                                    <i class="fas fa-search"></i>
                                </button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- /.card-header -->
                <div class="card-body table-responsive p-0">
                    <table class="table table-hover text-nowrap">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>Nome</th>
                                <th>Email</th>
                                <th>Tipo de Utilizador</th>
                                <th>Ações</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach ($users as $user)
                                <tr>
                                    <td>{{ $user->user_id }}</td>
                                    <td>{{ $user->user_name }}</td>
                                    <td>{{ $user->email }}</td>
                                    {{-- <td>{{ $user->user_type }}</td> --}}
                                    <td>{{ optional(\App\Models\TypeUser::find($user->type_users))->type_user }}</td>

                                    <td class="text-center d-flex justify-content-around">
                                        
                                        <a href="{{ route('users.Show', ['id' => $user->user_id]) }}">
                                            <i class="fa-solid fa-eye text-secondary"></i>
                                        </a>
                                        <a href="{{ route('users.edit', ['id' => $user->user_id]) }}">
                                            <i class="fa-solid fa-edit text-primary"></i>
                                        </a>
                                        {{-- <a href="#">
                                                <i class="fa-solid fa-trash-alt text-danger"></i>
                                            </a> --}}
                                        <form action="{{ route('users.destroy', $user) }}" method="POST"
                                            onsubmit="return confirm('Are you sure you want to delete this user?');"
                                            style="display:inline;">
                                            @csrf
                                            @method('DELETE')
                                            <button type="submit" class="btn btn-danger btn-sm">
                                                <i class="fa-solid fa-trash-alt text-white"></i>
                                            </button>
                                        </form>
                                    </td>
                                </tr>
                            @endforeach
                        </tbody>
                    </table>
                </div>
                <!-- /.card-body -->
            </div>
            <!-- /.card -->




        </div>
        {{-- /.container-fluid" --}}


    </section>
@endsection
