<?php
$usuarios = (new Usuario)->listar();
$mod = 'usuario';
$titulo = 'Usuários';
?>
<div class="row g-4">
    <div class="col-12">
        <nav class=" bg-secondary rounded h-100 p-4 navbar bg-body-tertiary">
            <div class="container-fluid">
                <a class="navbar-brand"><i class="fa fa-user me-2"> </i><?= $titulo ?></a>
                <div class="d-flex" role="search">
                    <a href="<?= __URLSITE__ ?><?= $mod ?>/formulario" type="button" class="btn btn-outline-primary">
                        Novo
                    </a>
                </div>
            </div>
        </nav>
    </div>

    <div class="col-12">
        <div class="bg-secondary rounded h-100 p-4">
            <div class="table-responsive">
                <table class="table">
                    <thead>
                        <tr>
                            <th scope="col">#</th>
                            <th scope="col">Login</th>
                            <th scope="col">Senha</th>
                            <th scope="col">Status</th><!-- Nível -->
                            <th scope="col">Ação</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($usuarios as $usuario) { ?>
                            <tr>
                                <td scope="row"><?= ($usuario)->usuario_id; ?></td>
                                <td><?= ($usuario)->usuario_login; ?></td>
                                <td><?= ($usuario)->usuario_senha; ?></td>
                                <td><?= ($usuario)->usuario_nivel; ?></td>
                                <td>
                                    <div class="btn-group" role="group">
                                        <button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
                                            Ação
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a class="dropdown-item btn-acao" type="button" href="<?= __URLSITE__ ?><?= $mod ?>/formulario/<?= ($usuario)->usuario_id; ?>"><i class="fas fa-edit me-2"></i>Editar</a></li>
                                            <li><a class="dropdown-item btn-acao" type="button" href="<?= __URLSITE__ ?><?= $mod ?>/excluir/<?= ($usuario)->usuario_id; ?>"><i class="far fa-trash-alt me-2"></i>Excluir</a></li>
                                        </ul>
                                    </div>
                                </td>
                            </tr>
                        <?php } ?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>


<script>
    $(document).ready(function() {
        var table = $('table').DataTable({
            // initComplete: function() {
            //     this.api().columns().every(function() {
            //         var that = this;
            //         $('input', this.footer()).on('keyup change clear', function() {
            //             if (that.search() !== this.value) {
            //                 that
            //                     .search(this.value)
            //                     .draw();
            //             }
            //         });
            //     });
            // },            
            "language": {
                "paginate": {
                "previous": "Anterior",
                "next": "Próxima"
                },
                "sSearch": "Pesquisar",
            },
        });
    });
</script>