<%- include('../layout') %>

<h1>Benutzerverwaltung</h1>

<table class="table table-striped">
  <thead>
    <tr>
      <th>ID</th>
      <th>Benutzername</th>
      <th>Rolle</th>
      <th>Aktionen</th>
    </tr>
  </thead>
  <tbody>
    <% users.forEach(u => { %>
      <tr>
        <td><%= u.id %></td>
        <td><%= u.username %></td>
        <td>
          <form action="/users/<%= u.id %>/role" method="post" class="d-flex">
            <select name="role" class="form-select form-select-sm me-2">
              <option value="user" <%= u.role === 'user' ? 'selected' : '' %>>User</option>
              <option value="admin" <%= u.role === 'admin' ? 'selected' : '' %>>Admin</option>
            </select>
            <button class="btn btn-sm btn-primary">Speichern</button>
          </form>
        </td>
        <td>
          <form action="/users/<%= u.id %>/delete" method="post" onsubmit="return confirm('Benutzer wirklich löschen?')">
            <button class="btn btn-sm btn-danger">Löschen</button>
          </form>
        </td>
      </tr>
    <% }) %>
  </tbody>
</table>

<%- include('../footer') %>
