{% extends 'base.html' %}

{% block title %}User Details - {{ user.username }} - LMS{% endblock %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h2>User Details</h2>
        <a href="{% url 'user_list' %}" class="btn btn-secondary">
            <i class="fas fa-arrow-left"></i> Back to Users
        </a>
    </div>

    <div class="row">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Basic Information</h5>
                </div>
                <div class="card-body">
                    <table class="table table-borderless">
                        <tr>
                            <th>Username:</th>
                            <td>{{ user.username }}</td>
                        </tr>
                        <tr>
                            <th>Email:</th>
                            <td>{{ user.email|default:"Not provided" }}</td>
                        </tr>
                        <tr>
                            <th>Full Name:</th>
                            <td>
                                {% if user.first_name or user.last_name %}
                                    {{ user.first_name }} {{ user.last_name }}
                                {% else %}
                                    Not provided
                                {% endif %}
                            </td>
                        </tr>
                        <tr>
                            <th>User Type:</th>
                            <td>
                                <span class="badge 
                                    {% if user.userprofile.user_type == 'student' %}bg-info
                                    {% elif user.userprofile.user_type == 'trainer' %}bg-warning
                                    {% elif user.userprofile.user_type == 'admin' %}bg-danger
                                    {% else %}bg-secondary{% endif %}">
                                    {{ user.userprofile.get_user_type_display }}
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <th>Status:</th>
                            <td>
                                <span class="badge bg-{% if user.is_active %}success{% else %}secondary{% endif %}">
                                    {% if user.is_active %}Active{% else %}Inactive{% endif %}
                                </span>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>

        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    <h5 class="mb-0">Account Information</h5>
                </div>
                <div class="card-body">
                    <table class="table table-borderless">
                        <tr>
                            <th>Date Joined:</th>
                            <td>{{ user.date_joined|date:"M d, Y H:i" }}</td>
                        </tr>
                        <tr>
                            <th>Last Login:</th>
                            <td>{{ user.last_login|date:"M d, Y H:i"|default:"Never" }}</td>
                        </tr>
                        <tr>
                            <th>Superuser:</th>
                            <td>
                                <span class="badge bg-{% if user.is_superuser %}danger{% else %}secondary{% endif %}">
                                    {% if user.is_superuser %}Yes{% else %}No{% endif %}
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <th>Staff:</th>
                            <td>
                                <span class="badge bg-{% if user.is_staff %}primary{% else %}secondary{% endif %}">
                                    {% if user.is_staff %}Yes{% else %}No{% endif %}
                                </span>
                            </td>
                        </tr>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <!-- User Activity Stats -->
    <div class="card mt-4">
        <div class="card-header">
            <h5 class="mb-0">User Activity</h5>
        </div>
        <div class="card-body">
            <div class="row text-center">
                <div class="col-md-3">
                    <div class="card bg-light">
                        <div class="card-body">
                            <h6>Assignments Submitted</h6>
                            <h3>0</h3>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-light">
                        <div class="card-body">
                            <h6>Resources Accessed</h6>
                            <h3>0</h3>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-light">
                        <div class="card-body">
                            <h6>Average Grade</h6>
                            <h3>0%</h3>
                        </div>
                    </div>
                </div>
                <div class="col-md-3">
                    <div class="card bg-light">
                        <div class="card-body">
                            <h6>Login Count</h6>
                            <h3>0</h3>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Action Buttons -->
    <div class="mt-4">
        <a href="{% url 'edit_user' user.pk %}" class="btn btn-primary">
            <i class="fas fa-edit"></i> Edit User
        </a>
        {% if not user.is_superuser %}
        <form action="{% url 'toggle_user_status' user.pk %}" method="post" class="d-inline">
            {% csrf_token %}
            <button type="submit" class="btn btn-{% if user.is_active %}warning{% else %}success{% endif %}">
                <i class="fas fa-{% if user.is_active %}times{% else %}check{% endif %}"></i>
                {% if user.is_active %}Deactivate{% else %}Activate{% endif %}
            </button>
        </form>
        {% endif %}
    </div>
</div>
{% endblock %}