<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
  <link th:href="@{/vendor/fontawesome-free/css/all.min.css}" rel="stylesheet">
  <link th:href="@{/css/sb-admin-2.min.css}" rel="stylesheet">
  <link rel="icon" href="data:,">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>

<body id="page-top">
  <div id="wrapper">
    <div th:replace="~{fragments/fragment-menu :: menu}"></div>
    <div id="content-wrapper" class="d-flex flex-column">
      <div id="content" class="p-4">

        <nav class="navbar navbar-expand navbar-light bg-white topbar mb-4 static-top shadow">
          <!-- Botón hamburguesa solo visible en móvil -->
          <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
            <i class="fa fa-bars"></i>
          </button>
          <h1 class="h4 mb-0 text-gray-800">Usuarios</h1>
        </nav>


        <div class="container-fluid">
          <a class="btn btn-primary mb-3" th:href="@{/usuarios/nuevo}">Nuevo</a>
          <div class="table-responsive">
            <table class="table table-bordered table-striped align-middle">
              <thead class="table-light">
                <tr>
                  <th>Usuario</th>
                  <th>Rol</th>
                  <th></th>
                </tr>
              </thead>
              <tbody>
                <tr th:each="u : ${usuarios}">
                  <td th:text="${u.username}">usuario</td>
                  <td th:text="${u.role}">ROLE_USER</td>
                  <td>
                    <a class="btn btn-sm btn-outline-primary" th:href="@{'/usuarios/' + ${u.id} + '/editar'}">Editar</a>
                    <form th:action="@{'/usuarios/' + ${u.id} + '/eliminar'}" method="post" class="d-inline"
                      onsubmit="return confirm('¿Eliminar este usuario y sus registros?');">
                      <input type="hidden" name="_method" value="delete" />
                      <button class="btn btn-sm btn-outline-danger" type="submit">Eliminar</button>
                    </form>
                  </td>

                </tr>
              </tbody>
            </table>
          </div>
        </div>

      </div>
    </div>
  </div>

  <script th:src="@{/vendor/jquery/jquery.min.js}"></script>
  <script th:src="@{/vendor/bootstrap/js/bootstrap.bundle.min.js}"></script>
  <script th:src="@{/js/sb-admin-2.min.js}"></script>

</body>

</html>