{% extends "app_home/base.html" %}
{% load static %}
{% load i18n %}

{% block navbar_app %}
{% include 'app_home/_sidebar.html' %}
{% endblock %}

{% block title %}
<h3><i class="fa fa-user" aria-hidden="true"></i> &nbsp; {{ user.displayname|default:user.login }}</h3>
<small class="text-muted">{% translate "Details" %}</small>
<hr>{% endblock %}

{% block content %}

<!-- UI action selector -->
<div class="dropdown">       
  <button class="btn btn-outline-dark dropdown-toggle" type="button" data-bs-toggle="dropdown">
      <i class="fa fa-lg fa-plus me-2"></i>{% translate 'Action' %}
  </button>

  <ul class="dropdown-menu">

      {% if 'p_user_update' in aaa.perms %}
      <li>
          <a class="dropdown-item" 
          href="{% url 'app_user:user_edit' user.id %}">
          {% translate 'Edit' %}
          </a>
      </li>{% endif %}
    



      {% if 'p_user_email_test' in aaa.perms  %}
      <li>
        <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#confirmModalEmail">
          {% translate "Test email" %}
        </a>
      </li>{% endif %}


      {% if 'p_user_sms_test' in aaa.perms  %}
      <li>
        <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#confirmModalSMS">
          {% translate "Test SMS" %}
        </a>
      </li>{% endif %}


      {% if 'p_user_delete' in aaa.perms %}
      <li>
          <a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#DeleteModal">
              {% translate "Delete" %}
          </a>
      </li>{% endif %}

      {% if 'p_iam_impersonate' in aaa.perms %}
      <li>
          <a class="dropdown-item" href="{% url 'app_user:impersonate' user.login %}">
              {% translate "Impersonate" %}
          </a>
      </li>{% endif %}


      {% if ui_texteditor %}
      <li><hr class="dropdown-divider"></li>
      <li>
        <a class="dropdown-item" href="{% url 'app_data:texteditor' '_user' user.id %}">
          {% translate "Code" %}</a>
      </li>
      {% endif %}



  </ul>
</div>



<hr>

<table class="table table-hover table-bordered table-sm">

  <tr class="table-primary">
    <td colspan="2">
        <div class="d-flex">
            <div class="flex me-2">
                  <strong>{{ user.displayname|default:user.login }}</strong>
            </div>
            <div class="flex ms-auto me-2"><!-- REVISIONS -->
                <div class="dropdown">
                    <button class="btn btn-outline-dark btn-sm dropdown-toggle" type="button"
                        data-bs-toggle="dropdown">
                        {% translate 'Revisions' %}
                    </button>
                    <ul class="dropdown-menu">
                        {% for rev in revisions %}
                        <li>
                            <pre>  {{ rev.date}} - {{ rev.action }} - {{  rev.username }}  </pre>
                        </li>
                        {% endfor %}
                    </ul>
                </div>
            </div>
        </div>
    </td>
  </tr>

  <tr><td class="table-light" width="20%">{% translate 'Is Enabled' %}</td>
  <td>{% if user.is_enabled %}<input type="checkbox" checked disabled/>
      {% else %}<input type="checkbox" disabled/>{% endif %}
  </td></tr>


  <tr><td class="table-light" width="20%">{% translate 'Login(*)' %}</td>
  <td>{{ user.login }}</td></tr>

  <tr><td class="table-light" width="20%">{% translate 'External ID' %}</td>
  <td>{{ user.external_id|default:'' }}</td></tr>

  <tr><td class="table-light" width="20%">{% translate 'Display name' %}</td>
  <td>{{ user.displayname|default:'' }}</td></tr>


  <tr><td class="table-light" width="20%">{% translate 'Firstname' %}</td>
  <td>{{ user.firstname|default:'' }}</td></tr>

  <tr><td class="table-light" width="20%">{% translate 'Lastname' %}</td>
  <td>{{ user.lastname|default:'' }}</td></tr>

  <tr><td class="table-light" width="20%">{% translate 'Email' %}</td>
  <td>{{ user.email|default:'' }}</td></tr>

  <tr><td class="table-light" width="20%">{% translate 'Mobile' %}</td>
    <td>{{ user.mobile|default:'' }}</td></tr>

  <tr><td class="table-light" width="20%">{% translate 'Description' %}</td>
  <td>{{ user.description|default:'' }}</td></tr>


  <tr><td class="table-light" width="20%">{% translate 'Last login' %}</td>
  <td>{{ user.last_login|default:'' }}</td></tr>

  <tr><td class="table-light" width="20%">{% translate 'Last update' %}</td>
  <td>{{ user.last_update|default:'' }}</td></tr>


</table>

<hr>


<!-- GROUPS -->
<table class="table table-hover table-bordered table-sm small">
<tr class="table-success"><td colspan="4"><strong>{% translate 'Groups' %}</strong></td></tr>
<tr>
<td class="table-light">
    <div class="d-flex flex-wrap"> 
    {% for z in direct %}
      {% if not z.is_role %}
        <a class="btn btn-success btn-sm mx-1 my-1" href="{% url 'app_user:group_detail' z.id %}" role="button">{{ z.keyname }}</a>
      {% endif %}
    {% endfor %}
    
    {% for z in indirect %}
      {% if not z.is_role %}
        <a class="btn btn-outline-success btn-sm mx-1 my-1" href="{% url 'app_user:group_detail' z.id %}" role="button">{{ z.keyname }}</a>
      {% endif %}
    {% endfor %}       

    {% for z in computed %}
    {% if not z.is_role %}
      <a class="btn btn-outline-dark btn-sm mx-1 my-1" href="{% url 'app_user:group_detail' z.id %}" role="button">(Auto) {{ z.keyname }}</a>
    {% endif %}
  {% endfor %}       
  

    </div>   
</td></tr>
</table>

<!-- ROLES -->
<table class="table table-hover table-bordered table-sm small">
<tr class="table-danger"><td colspan="4"><strong>{% translate 'Roles' %}</strong></td></tr>
<tr>
<td class="table-light">
    <div class="d-flex flex-wrap"> 
    {% for z in direct %}
      {% if z.is_role %}
        <a class="btn btn-danger btn-sm mx-1 my-1" href="{% url 'app_user:role_detail' z.id %}" role="button">{{ z.keyname }}</a>
      {% endif %}
    {% endfor %}
    {% for z in indirect %}
      {% if z.is_role %}
        <a class="btn btn-outline-danger btn-sm mx-1 my-1" href="{% url 'app_user:role_detail' z.id %}" role="button">{{ z.keyname }}</a>
      {% endif %}
    {% endfor %}
    </div>   
</td></tr>
</table>


<!-- PERMISSIONS -->
<table class="table table-hover table-bordered table-sm small">
<tr class="table-warning"><td colspan="4"><strong>{% translate 'Permissions' %}</strong></td></tr>
<tr>
{% for perm in permissions %}
<td class="table-light" width="20%">{{ perm.keyname }}</td>
<td>{{ perm.appname|default:'' }}</td>
<td>{{ perm.displayname|default:'' }}</td>
<td>{{ perm.description|default:'' }}</td>
</tr>{%  endfor %}
</table>




<!-- DELETE CONFIRM Modal -->
{% if user %}

<div class="modal fade" id="DeleteModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">

<div class="modal-header">
<h1 class="modal-title fs-5" id="staticBackdropLabel">{% translate "Confirm delete ?" %}</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
    
<div class="modal-body">
<p>User: {{ user.displayname|default:user.login }}</p>
</div>

<div class="modal-footer">
<form action="{% url 'app_user:user_delete' user.id %}" method="post">{% csrf_token %}
<button role="button" class="btn btn-danger">{% translate "Delete" %}</button>
<a role="button" class="btn btn-outline-dark" data-dismiss="modal">{% translate "Cancel" %}</a>
</form>
</div>

</div>
</div>
</div>




<!-- modals / confirm SEND EMAIL -->
<div class="modal fade" id="confirmModalEmail" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1">
  <div class="modal-dialog">
  <div class="modal-content">
  
  <div class="modal-header">
  <h1 class="modal-title fs-5" id="staticBackdropLabel">{% translate "Send test EMAIL ?" %}</h1>
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  </div>
      
  <div class="modal-body">
  <p>Login: {{ user.login|default:'n/a' }}</p>
  <p>Email: {{ user.email|default:'n/a' }}</p>
  </div>
  
  <div class="modal-footer">
  <form action="{% url 'app_user:email_test' user.id %}" method="post">{% csrf_token %}
  <button role="button" class="btn btn-danger">{% translate "Send" %}</button>
  <a role="button" class="btn btn-outline-dark" data-bs-dismiss="modal">{% translate "Cancel" %}</a>
  </form>
  </div>
  
  </div>
  </div>
  </div>
  
  
  
  <!-- modals / confirm SEND SMS -->
  <div class="modal fade" id="confirmModalSMS" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1">
  <div class="modal-dialog">
  <div class="modal-content">
  
  <div class="modal-header">
  <h1 class="modal-title fs-5" id="staticBackdropLabel">{% translate "Send test SMS ?" %}</h1>
  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  </div>
      
  <div class="modal-body">
  <p>Login: {{ user.login|default:'n/a' }}</p>
  <p>Mobile: {{ user.mobile|default:'n/a' }}</p>
  </div>
  
  <div class="modal-footer">
  <form action="{% url 'app_user:sms_test' user.id %}" method="post">{% csrf_token %}
  <button role="button" class="btn btn-danger">{% translate "Send" %}</button>
  <a role="button" class="btn btn-outline-dark" data-bs-dismiss="modal">{% translate "Cancel" %}</a>
  </form>
  </div>
  
  </div>
  </div>
  </div>



{% endif %}


{% endblock %}



