{% extends "authentic2/manager/form.html" %}
{% load i18n static %}

{% block appbar %}
  {{ block.super }}
  <span class="actions">
    <a class="extra-actions-menu-opener"></a>

  {% if view.can_delete %}
    <a rel="popup" href="{% url "a2-manager-user-delete" pk=object.pk %}">{% trans "Delete" %}</a>
  {% else %}
    <a class="disabled" title="{% trans "You do not have the rights to delete this user." %}" href="#">{% trans "Delete" %}</a>
  {% endif %}

  {% if view.can_change %}
    <a href="{% url "a2-manager-user-edit" pk=object.pk %}">{% trans "Edit" %}</a>
  {% else %}
    <a class="disabled" title="{% trans "You do not have the rights to edit this user." %}" href="#">{% trans "Edit" %}</a>
  {% endif %}

    <ul class="extra-actions-menu">
      {% if view.is_oidc_services %}
      <li><a href="{% url "a2-manager-user-authorizations" pk=object.pk %}">{% trans "Consents" %}</a></li>
      {% endif %}
      <li><a href="{% url "a2-manager-user-journal" pk=object.pk %}">{% trans "Journal" %}</a></li>
    </ul>
  </span>
{% endblock %}

{% block breadcrumb %}
  {{ block.super }}
  <a href="../">{% trans 'Users' %}</a>
  {% if multiple_ou and object.ou %}
    <a href="../?search-ou={{ object.ou.pk }}">{{ object.ou }}</a>
  {% endif %}
  <a href="#">{{ object.get_full_name }}</a>
{% endblock %}

{% block afterform %}
  {% if object.passwordreset_set.exists %}
    <div class="warning-box">{% trans "User must change its password on next access to authentic" %}
      <button name="delete_password_reset">{% trans "Cancel this constraint" %}</button>
    </div>
  {% endif %}
{% endblock %}

{% block buttons %}
{% endblock %}

{% block sidebar %}
<aside id="sidebar">

  <p class="a2-manager-user-last-login">
    {% if object.last_login %}
      {% blocktrans with date=object.last_login %}Last login on {{ date }}.{% endblocktrans %}
    {% else %}
      {% trans "Never logged in." %}
    {% endif %}
  </p>

  <p class="a2-manager-user-date-joined">
    {% blocktrans with date=object.date_joined %}Created on {{ date }}{% endblocktrans %}
  </p>

  {% if object.date_joined != object.modified %}
    <p class="a2-manager-user-modified">
      {% blocktrans with date=object.modified %}Modified on {{ date }}{% endblocktrans %}
    </p>
  {% endif %}

  {% if not object.is_active and object.deactivation %}
  <p class="a2-manager-user-date-deactivated">
    {% blocktrans with date=object.deactivation %}Deactivated on {{ date }}{% endblocktrans %}
  </p>
  {% endif %}

  {% for data in user_data %}
    {{ data }}
  {% endfor %}

  {% block other_actions %}{{ block.super }}{% endblock %}

  {% if roles_by_ou or can_change_roles %}
  <div class="user-roles">
    <h3>{% trans "Roles" %}</h3>
    <ul>
      {% for ou, ou_roles in roles_by_ou.items %}
        {% if have_roles_on_multiple_ou %}
       <li>{% if ou %}{{ ou }}{% else %}{% trans "All organizational units" %}{% endif %}
              <ul>
        {% endif %}
              {% for role in ou_roles %}
                <li {% if role.description %}title="{{ role.description }}"{% endif %}>
                {% if role.user_visible %}<a href="{% url "a2-manager-role-members" pk=role.pk %}">{{ role }}</a>{% else %}{{ role }}{% endif %}</li>
              {% endfor %}
        {% if have_roles_on_multiple_ou %}
              </ul>
          </li>
        {% endif %}
      {% endfor %}
    </ul>

    {% if can_change_roles %}
      <button onclick="window.location.href = '{% url "a2-manager-user-roles" pk=object.pk %}?search-ou={% firstof object.ou.pk default_ou.pk %}'; return false">{% trans "Modify roles" %}</button>
    {% endif %}
  </div>
  {% endif %}

</aside>
{% endblock %}
