{% extends "authentic2/base.html" %}
{% load i18n %}

{% if service_custom_appearance %}
  {% block extra-top-head %}
    {{ block.super }}
    {% firstof generic_service_colour service_colour service_ou_colour as colour %}
    {% if colour %}
      <style>
        .gru-content div#a2-service-information h2 {
          color: {{ colour }};
        }
      </style>
    {% endif %}
  {% endblock %}
{% endif %}

{% block title %}Gestion du compte{% endblock %}
{% block extra-body-class %}{{ block.super }} account-page{% endblock %}

{% block content %}
  {% block before-main-content %}
    {{ block.super }}
    {% if service_custom_appearance %}
      {% firstof generic_service_name service.name service.ou.name as name %}
      {% firstof generic_service_logo_url service_logo_url service_ou_logo_url as logo_url %}
      <div id="a2-service-information" class="service-message">
        <h2>{{ name }}</h2>
        <div class="cell--body">
          {% if logo_url %}
            <picture>
              {% if service.home_url or generic_service_home_url %}
                <a href="{% firstof service.home_url generic_service_home_url %}">
              {% endif %}
              <img src="{{ logo_url }}" alt=""/>
              {% if service.home_url or generic_service_home_url %}
                </a>
              {% endif %}
            </picture>
          {% endif %}
        </div>
      </div>
    {% endif %}
  {% endblock %}

  <div class="column profile">
    {% block profile-pre %}{% endblock %}
    <div class="block" id="a2-profile">
      {% block profile-top %}{% endblock %}
      {% block profile-data-title %}
        <h2>Données du compte</h2>
      {% endblock %}
      {% block profile-data %}
        <div id="profile" class="cell--body">
          <dl>
            {% if attributes %}
              {% for attribute in attributes %}
                <dt class="label">{{ attribute.attribute.label|capfirst }}</dt>
                <dd class="value">
                  {% if attribute.values|length == 0 %}<span class="nodata">(non spécifié)</span>
                  {% elif attribute.values|length == 1 %}{{ attribute.values.0 }}{% else %}
                    <ul>
                      {% for value in attribute.values %}
                        <li>{{ value }}</li>
                      {% endfor %}
                    </ul>
                  {% endif %}
                </dd>
              {% endfor %}
            {% endif %}
            {% if LAST_LOGIN %}
              <dt class="label">Dernière connexion</dt>
              <dd class="value">{{ LAST_LOGIN }}</dd>
            {% endif %}
          </dl>
        </div>
      {% endblock %}
      {% block profile-bottom %}{% endblock %}
    </div>
    {% block profile-post %}{% endblock %}
  </div>
  <div class="column account-management">
    {% block account-management-pre %}{% endblock %}
    <div class="block" id="account-management">
      {% block account-management-top %}{% endblock %}
      {% block account-management-title %}
        <h2>Gestion du compte</h2>
      {% endblock %}
      {% block account-management-actions %}
        <div class="links-list">
          <ul class="account-management">
            {% block account-management-top-actions %}
            {% endblock %}
            {% if allow_email_change %}
              <li class="email-change"><a href="{% url 'email-change' %}">{% if email %}Modifier le courriel associé{% else %}Définir son adresse courriel{% endif %}</a></li>
            {% endif %}
            {% if allow_phone_change %}
              <li class="phone-change"><a href="{% url 'phone-change' %}">{% if phone %}Modifier le numéro de téléphone associé{% else %}Définir son numéro de téléphone{% endif %}</a></li>
            {% endif %}
            {{ frontends_block_by_id.password.content|safe }}
            {% if profile_edit_url %}
              <li class="profile-edit"><a href="{{ profile_edit_url }}">Modifier les données du compte</a></li>
            {% elif allow_profile_edit %}
              <li class="profile-edit"><a href="{% url 'profile_edit' %}">Modifier les données du compte</a></li>
            {% endif %}
            {% if allow_authorization_management %}
              <li><a href="{% url 'consents' %}">Gérer les autorisations d’accès</a></li>
            {% endif %}
            {% if allow_account_deletion %}
              <li class="account-delete"><a href="{% url 'delete_account' %}">Supprimer le compte</a></li>
            {% endif %}
            {% block account-management-bottom-actions %}
            {% endblock %}
          </ul>
        </div>
      {% endblock %}
    </div>
    {% block account-management-other-blocks %}
      {% for id, block in frontends_block_by_id.items %}
        {% if id != "password" %}
          <div class="block" id="account-management-{{ id }}">
            <h2>{{ block.name }}</h2>
            <div class="cell--body">
              {{ block.content|safe }}
            </div>
          </div>
        {% endif %}
      {% endfor %}
    {% endblock %}
    {% block account-management-post %}{% endblock %}
  </div>
{% endblock %}
