{% 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="card sp-animate-card">
        <div class="card-header d-flex justify-content-between align-items-center">
            <div>
                <h6 class="card-title mb-0">System Users</h6>
                <small class="text-muted">Manage managers, cashiers and admins.</small>
            </div>
            <a href="{% url 'user_create' %}" class="btn btn-sm btn-primary">
                <i class="fas fa-user-plus me-1"></i> Add User
            </a>
        </div>
        <div class="card-body">
            <div class="sp-table-container">
                <table>
                    <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 %}
