{% extends 'base.html' %}
{% load static %}

{% block content %}
<section class="hero-bw">
    <div class="hero-content">
        <div class="container py-5">
            <div class="row">
                <div class="col-md-4 mb-4">
                    <div class="card border-bw bg-transparent text-bw h-100">
                        <div class="card-body text-center">
                            {% if user.profile.avatar %}
                                <img src="{{ user.profile.avatar.url }}" alt="{{ user.username }}" class="rounded-circle mb-3 border-bw" style="width: 150px; height: 150px; object-fit: cover;">
                            {% else %}
                                <div class="rounded-circle mb-3 border-bw d-inline-flex align-items-center justify-content-center bg-bw text-bw-reverse" style="width: 150px; height: 150px; font-size: 3rem;">
                                    {{ user.username|first|upper }}
                                </div>
                            {% endif %}
                            <h2 class="text-uppercase mb-0">{{ user.username }}</h2>
                            <p class="text-muted small">{{ user.email }}</p>
                            <hr class="border-bw">
                            <div class="text-start">
                                <p class="mb-1"><strong class="text-uppercase small">Location:</strong> {{ user.profile.location|default:"NOT_SET" }}</p>
                                <p class="mb-1"><strong class="text-uppercase small">Joined:</strong> {{ user.date_joined|date:"M d, Y" }}</p>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-8">
                    <div class="card border-bw bg-transparent text-bw mb-4">
                        <div class="card-body">
                            <h3 class="text-uppercase mb-4">UPDATE_PROFILE</h3>
                            <form method="POST" enctype="multipart/form-data">
                                {% csrf_token %}
                                <div class="row">
                                    <div class="col-md-6 mb-3">
                                        <label class="text-uppercase small fw-bold">Username</label>
                                        {{ u_form.username }}
                                    </div>
                                    <div class="col-md-6 mb-3">
                                        <label class="text-uppercase small fw-bold">Email</label>
                                        {{ u_form.email }}
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6 mb-3">
                                        <label class="text-uppercase small fw-bold">First Name</label>
                                        {{ u_form.first_name }}
                                    </div>
                                    <div class="col-md-6 mb-3">
                                        <label class="text-uppercase small fw-bold">Last Name</label>
                                        {{ u_form.last_name }}
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <label class="text-uppercase small fw-bold">Bio</label>
                                    {{ p_form.bio }}
                                </div>
                                <div class="row">
                                    <div class="col-md-6 mb-3">
                                        <label class="text-uppercase small fw-bold">Location</label>
                                        {{ p_form.location }}
                                    </div>
                                    <div class="col-md-6 mb-3">
                                        <label class="text-uppercase small fw-bold">Birth Date</label>
                                        {{ p_form.birth_date }}
                                    </div>
                                </div>
                                <div class="mb-3">
                                    <label class="text-uppercase small fw-bold">Avatar</label>
                                    {{ p_form.avatar }}
                                </div>
                                <button type="submit" class="btn btn-bw text-uppercase w-100 mt-3">SAVE_CHANGES</button>
                            </form>
                        </div>
                    </div>

                    <div class="card border-bw bg-transparent text-bw">
                        <div class="card-body">
                            <h3 class="text-uppercase mb-4">YOUR_PROGRESS</h3>
                            {% if user_progress %}
                                <div class="table-responsive">
                                    <table class="table table-bw text-bw mb-0">
                                        <thead class="text-uppercase small">
                                            <tr>
                                                <th>COURSE</th>
                                                <th>LESSON</th>
                                                <th>COMPLETED</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            {% for progress in user_progress %}
                                                <tr>
                                                    <td>{{ progress.lesson.module.course.title }}</td>
                                                    <td>
                                                        <a href="{% url 'lesson_detail' progress.lesson.pk %}" class="text-bw">{{ progress.lesson.title }}</a>
                                                    </td>
                                                    <td>{{ progress.completed_at|date:"M d, Y" }}</td>
                                                </tr>
                                            {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            {% else %}
                                <p class="text-muted">YOU_HAVENT_STARTED_ANY_LESSONS_YET</p>
                                <a href="{% url 'home' %}" class="btn btn-bw-outline text-uppercase">BROWSE_COURSES</a>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<style>
    .form-control, .form-select {
        background-color: transparent !important;
        border: 2px solid #000 !important;
        color: #000 !important;
        border-radius: 0 !important;
        font-family: var(--bs-font-monospace);
    }
    [data-theme="dark"] .form-control, [data-theme="dark"] .form-select {
        border-color: #fff !important;
        color: #fff !important;
    }
    .table-bw {
        border-color: #000;
    }
    [data-theme="dark"] .table-bw {
        border-color: #fff;
    }
    .table-bw td, .table-bw th {
        border-color: inherit;
        background-color: transparent !important;
        color: inherit !important;
    }
</style>
