<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Active Sessions</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-5">
        <h1 class="mb-4">Active Sessions</h1>
        {% if messages %}
            <div class="alert alert-success">
                {% for message in messages %}
                    {{ message }}
                {% endfor %}
            </div>
        {% endif %}
        <div class="table-responsive">
            <table class="table table-striped">
                <thead>
                    <tr>
                        <th>Device</th>
                        <th>IP Address</th>
                        <th>Browser</th>
                        <th>Last Activity</th>
                        <th>Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for session in sessions %}
                    <tr>
                        <td>
                            <i class="fas fa-laptop"></i> {{ session.device_info }}
                        </td>
                        <td>{{ session.ip_address }}</td>
                        <td>
                            <i class="fab {{ session.browser_icon }}"></i> {{ session.browser_info }}
                        </td>
                        <td>{{ session.last_activity|date:"Y-m-d H:i:s" }}</td>
                        <td>
                            <form method="POST" action="{% url 'delete_user_session' session.session_id %}">
                                {% csrf_token %}
                                <button type="submit" class="btn btn-danger btn-sm">
                                    <i class="fas fa-trash"></i> Delete
                                </button>
                            </form>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="5">No active sessions found.</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
