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

{% block title %}ملفي الشخصي | EduPlatform{% endblock %}

{% block content %}
<section class="hero-section text-center pt-5 pb-5">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-lg-8">
                <div class="glass-card text-start">
                    <div class="d-flex align-items-center mb-4">
                        {% if student_profile and student_profile.avatar %}
                            <img src="{{ student_profile.avatar.url }}" alt="Profile" class="rounded-circle me-3" width="100" height="100" style="object-fit: cover; border: 3px solid var(--primary-color);">
                        {% else %}
                            <div class="rounded-circle bg-secondary d-flex align-items-center justify-content-center me-3" style="width: 100px; height: 100px; color: white; font-size: 2rem;">
                                {{ user.username|make_list|first|upper }}
                            </div>
                        {% endif %}
                        <div>
                            <h2 class="mb-1">{{ user.get_full_name|default:user.username }}</h2>
                            <p class="text-muted mb-0">{{ user.email }}</p>
                            {% if student_profile and student_profile.classroom %}
                                <span class="badge bg-primary">{{ student_profile.classroom.name_ar }}</span>
                            {% elif user.is_staff %}
                                <span class="badge bg-success">طاقم / مسؤول</span>
                            {% endif %}
                        </div>
                    </div>

                    <hr class="my-4">

                    {% if student_profile %}
                        <h4 class="mb-3">تفاصيل الطالب</h4>
                        <div class="row">
                            <div class="col-md-6 mb-3">
                                <label class="form-label text-muted">اسم المستخدم</label>
                                <p class="fw-bold">{{ user.username }}</p>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label text-muted">المدينة</label>
                                <p class="fw-bold">{{ student_profile.city.name_ar|default:"-" }}</p>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label text-muted">المحافظة</label>
                                <p class="fw-bold">{{ student_profile.governorate.name_ar|default:"-" }}</p>
                            </div>
                            <div class="col-md-6 mb-3">
                                <label class="form-label text-muted">رقم الهاتف</label>
                                <p class="fw-bold">{{ student_profile.mobile_number|default:"-" }}</p>
                            </div>
                        </div>

                        <h4 class="mb-3 mt-4">موادي</h4>
                        {% if student_profile.subscribed_subjects.all %}
                            <div class="list-group">
                                {% for subject in student_profile.subscribed_subjects.all %}
                                    <a href="{% url 'subject_detail' subject.pk %}" class="list-group-item list-group-item-action d-flex justify-content-between align-items-center">
                                        {{ subject.name_ar }}
                                        <span class="badge bg-secondary rounded-pill">عرض</span>
                                    </a>
                                {% endfor %}
                            </div>
                        {% else %}
                            <p class="text-muted">لم يتم الاشتراك في أي مواد بعد.</p>
                        {% endif %}
                    {% else %}
                        <div class="alert alert-info">
                            أنت مسجل دخول كعضو طاقم أو مستخدم بدون ملف طالب.
                        </div>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}