{% extends 'users/base.html' %}

{% block title %}User Management{% endblock %}

{% block card_content %}
<div class="table-responsive">
    <table class="table table-striped">
        <thead>
            <tr>
                <th>Name</th>
                <th>Email</th>
                <th>Role</th>
                <th>Department</th>
                <th>Status</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            {% for user in users %}
            <tr>
                <td>{{ user.get_full_name|default:user.email }}</td>
                <td>{{ user.email }}</td>
                <td>{{ user.role.name|default:"-" }}</td>
                <td>{{ user.department.name|default:"-" }}</td>
                <td>
                    <span class="badge {% if user.is_active %}bg-success{% else %}bg-danger{% endif %}">
                        {% if user.is_active %}Active{% else %}Inactive{% endif %}
                    </span>
                </td>
                <td>
                    <a href="{% url 'users:user_detail' user.pk %}" class="btn btn-sm btn-info">View</a>
                    <a href="{% url 'users:user_update' user.pk %}" class="btn btn-sm btn-warning">Edit</a>
                    {% if request.user.is_superuser %}
                    <a href="{% url 'users:user_delete' user.pk %}" class="btn btn-sm btn-danger" 
                       onclick="return confirm('Are you sure you want to delete this user?')">Delete</a>
                    {% endif %}
                </td>
            </tr>
            {% empty %}
            <tr>
                <td colspan="6" class="text-center">No users found.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}

{% block card_footer %}
<a href="{% url 'users:user_create' %}" class="btn btn-primary">
    <i class="fas fa-plus"></i> Add New User
</a>
{% endblock %}
