{% extends "core/base.html" %}
{% load static %}

{% block title %}Users - SwiftPOS{% endblock %}
{% block topbar_title %}Users{% endblock %}

{% block content %}
<div class="container-fluid px-0">

    <div class="sp-page-header">
        <div>
            <h1 class="sp-page-title"><i class="fas fa-users-cog"></i>System Users</h1>
            <p class="sp-page-subtitle">Manage managers, cashiers and admins.</p>
        </div>
        <a href="{% url 'user_create' %}" class="btn btn-sm btn-primary d-flex align-items-center gap-2">
            <i class="fas fa-user-plus"></i> Add User
        </a>
    </div>

    <div class="card sp-animate-card">
        <div class="card-body p-0">
            <div class="sp-table-container">
                <table class="table table-hover align-middle mb-0">
                    <thead>
                        <tr>
                            <th>Username</th>
                            <th>Full Name</th>
                            <th>Role</th>
                            <th>Branch</th>
                            <th>Status</th>
                            <th>Last Login</th>
                            <th class="text-end">Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for user in users %}
                            <tr>
                                <td>{{ user.username }}</td>
                                <td>{{ user.get_full_name|default:user.username }}</td>
                                <td>{{ user.get_role_display }}</td>
                                <td>
                                    {% if user.branch %}
                                        {{ user.branch.name }}
                                    {% else %}
                                        <span class="text-muted small">No branch</span>
                                    {% endif %}
                                </td>
                                <td>
                                    {% if user.is_active %}
                                        <span class="badge bg-success-subtle">Active</span>
                                    {% else %}
                                        <span class="badge bg-danger-subtle">Inactive</span>
                                    {% endif %}
                                </td>
                                <td>
                                    {% if user.last_login %}
                                        {{ user.last_login|date:"Y-m-d H:i" }}
                                    {% else %}
                                        <span class="text-muted small">Never</span>
                                    {% endif %}
                                </td>
                                <td class="text-end">
                                    <a href="{% url 'user_edit' user.pk %}" class="btn btn-sm btn-outline-secondary">
                                        Edit
                                    </a>
                                </td>
                            </tr>
                        {% empty %}
                            <tr>
                                <td colspan="7" class="text-center text-muted py-3">
                                    No users found.
                                </td>
                            </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
{% endblock %}
