{% extends 'base.html' %}
{% block body %}
<div class="row mt-5">
  <div>
    <h1>Users</h1>
  </div>
</div>
<div class="row">
  <div class="col-10"></div>
  <div class="col-2 mb-2">
    <a href="{{url_for('dashboard.create_user')}}" class="btn btn-primary">New user</a>
  </div>
</div>
<table class="table">
  <thead>
    <tr>
      <th>#</th>
      <th>username</th>
      <th>email</th>
      <th>role</th>
      <th>status</th>
      <th>actions</th>
    </tr>
  </thead>
  <tbody>
    {% for user in users %}
    <tr>
      <td>{{user.id}}</td>
      <td><a href="{{url_for('dashboard.user_detail', user_id=user.id)}}">{{user.username}}</a></td>
      <td>{{user.email}}</td>
      <td>{{user.role}}</td>
      <td>
        {% if user.is_active %}
        <span class="badge badge-success">active</span>
        {% else %}
        <span class="badge badge-danger">inactive</span>
        {% endif %}
      </td>
      <td>
        <a href="{{url_for('dashboard.delete_user', user_id=user.id)}}" class="btn btn-danger btn-sm" onclick="return confirm('are you sure you want to delete this user ?');">delete</a>
      </td>
    </tr>
    {% endfor %}
  </tbody>
</table>
{% endblock %}
