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

{% block title %}تعديل ملف المعلم - EduPlatform{% endblock %}

{% block content %}
<div class="container" style="margin-top: 100px; margin-bottom: 50px;">
    <div class="row justify-content-center">
        <div class="col-md-8 col-lg-6">
            <div class="card shadow border-0 rounded-4">
                <div class="card-body p-4 p-md-5">
                    <h3 class="fw-bold text-center mb-4">تعديل الملف الشخصي</h3>
                    
                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                        
                        <!-- Avatar Preview -->
                        <div class="text-center mb-4">
                            <div class="position-relative d-inline-block">
                                {% if form.instance.avatar %}
                                    <img src="{{ form.instance.avatar.url }}" alt="Avatar" class="rounded-circle img-thumbnail" style="width: 120px; height: 120px; object-fit: cover;">
                                {% else %}
                                    <div class="rounded-circle bg-light d-flex align-items-center justify-content-center mx-auto" style="width: 120px; height: 120px;">
                                        <span class="text-muted display-4">{{ user.first_name|first|upper }}</span>
                                    </div>
                                {% endif %}
                            </div>
                        </div>

                        {% for field in form %}
                            <div class="mb-3">
                                <label for="{{ field.id_for_label }}" class="form-label fw-semibold">{{ field.label }}</label>
                                {{ field }}
                                {% if field.help_text %}
                                    <div class="form-text text-muted">{{ field.help_text }}</div>
                                {% endif %}
                                {% for error in field.errors %}
                                    <div class="invalid-feedback d-block">
                                        {{ error }}
                                    </div>
                                {% endfor %}
                            </div>
                        {% endfor %}

                        <div class="d-grid gap-2 mt-4">
                            <button type="submit" class="btn btn-primary btn-lg rounded-pill fw-bold">
                                حفظ التغييرات
                            </button>
                            <a href="{% url 'profile' %}" class="btn btn-outline-secondary rounded-pill">
                                إلغاء
                            </a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}