{# templates/profiles/edit_profile.html #}
{% extends 'base.html' %}
{% block title %}Editar Perfil{% endblock %}

{% block content %}
<div class="container mx-auto px-4 py-8">
  <div class="max-w-2xl mx-auto">
    <h1 class="text-3xl font-bold mb-6">Editar Perfil</h1>

    <div class="card">
      <div class="card-h">
        <h2 class="text-xl font-bold">Información del Perfil</h2>
        <p class="text-sm mt-1" style="color: var(--muted-foreground);">Actualiza tu información pública</p>
      </div>

      <div class="card-c">
        <form method="post" enctype="multipart/form-data" class="space-y-5">
          {% csrf_token %}

          {% if form.non_field_errors %}
            <div class="p-3 rounded-lg border" style="border-color: var(--border); background: rgba(212,24,61,.06);">
              <div class="text-sm" style="color: var(--destructive);">
                {{ form.non_field_errors }}
              </div>
            </div>
          {% endif %}

          {# Render simple y bonito sin necesitar tocar forms.py #}
          {% for field in form %}
            <div class="field">
              <label class="label" for="{{ field.id_for_label }}">{{ field.label }}</label>
              {{ field }}
              {% if field.help_text %}
                <p class="help">{{ field.help_text }}</p>
              {% endif %}
              {% if field.errors %}
                <p class="text-sm" style="color: var(--destructive);">{{ field.errors|striptags }}</p>
              {% endif %}
            </div>
          {% endfor %}

          <div class="flex gap-3 pt-2">
            <button type="submit" class="btn btn-primary">Guardar Cambios</button>
            <a href="{% url 'edit_profile' %}" class="btn btn-outline">Cancelar</a>
          </div>

          <script>
            // Aplica clases a inputs generados por Django forms (sin tocar Python)
            (function(){
              const root = document.currentScript?.closest('form');
              if(!root) return;
              root.querySelectorAll('input[type="text"], input[type="email"], input[type="password"], input[type="file"], input[type="url"], input[type="number"], textarea, select')
                .forEach(el => el.classList.add('input'));
            })();
          </script>
        </form>
      </div>
    </div>
  </div>
</div>
{% endblock %}