@extends('Templates/templateAdmin')

@section('Main-content')
    @if (session('success'))
        <div class="alert alert-success">
            {{ session('success') }}
        </div>
    @endif

    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1 class="text-light">Empresas</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item active">Administração</li>
                        <li class="breadcrumb-item active">Empresas</li>
                    </ol>
                </div>
            </div>
        </div>
    </section>

    <section class="content">
        <div class="container-fluid">
            <div class="card-light">
                <div class="card-header">
                    <h3 class="card-title">Tabela Utilizadores</h3>
                </div>
                <!-- /.card-header -->
                <div class="card-body">
                    <div class="table-responsive">
                        <table class="table table-hover text-nowrap" id="TableReceiveAllUsers">
                            <thead>
                                <tr>
                                    <th>ID</th>
                                    <th>Nome</th>
                                    <th>Email</th>
                                    <th>Tipo de Utilizador</th>
                                    <th>Ações</th>
                                </tr>Empresas
                            </thead>
                            <tbody>
                                @foreach ($users as $user)
                                    <tr>
                                        <td>{{ $user->user_id }}</td>
                                        <td>{{ $user->user_name }}</td>
                                        <td>{{ $user->email }}</td>
                                        <td>{{ $user->userType->type_user }}</td>
                                        <td class="table-btn-group-al">
                                            <div class="d-flex justify-content-center dropdown">
                                                <button data-toggle="dropdown" aria-expanded="false"
                                                    class="actions-btn btn btn-light circle ">
                                                    <i class="fa fa-ellipsis-v"></i>
                                                </button>
                                                <div id="group-actions-btn-14" class="dropdown-menu dropdown-menu-light">
                                                    <a href="{{ route('users.Show', ['id' => $user->user_id]) }}"
                                                        class="dropdown-item text-light">
                                                        <i class="fa-solid fa-eye text-light"></i>
                                                        Detalhes
                                                    </a>
                                                    <a href="{{ route('users.edit', ['id' => $user->user_id]) }}"
                                                        class="dropdown-item text-light">
                                                        <i class="fa-solid fa-edit text-light"></i>
                                                        Editar
                                                    </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="dropdown-item text-danger">
                                                            <i class="fa-solid fa-trash-alt text-danger"></i>
                                                            Excluir
                                                        </button>
                                                    </form>
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
                <!-- /.card-body -->
            </div>
            <!-- /.card -->
        </div>
        {{-- /.container-fluid" --}}
    </section>
@endsection

@section('scriptsTemplateAdmin')
    <script>
        $(function() {
            $("#TableReceiveAllUsers").DataTable({
                "responsive": true,
                "lengthChange": false,
                "autoWidth": false,
                "buttons": ["copy", "csv", "excel", "pdf", "print", "colvis"]
            }).buttons().container().appendTo('#TableReceiveAllUsers_wrapper .col-md-6:eq(0)');
        });
    </script>
@endsection
