{% extends "base.html" %}

{% block content %}
<br>
<div class="text-center">
  <p>{{ 'Are you available in case of alert?'|t }}</p>
  <form method="post">
    <input type="hidden" name="token_list" value="{{ token_list }}"/>
    <input type="hidden" name="action" value="activate"/>
    <input type="hidden" name="user_id" value="{{ user.id }}"/>
    <button type="submit" class="btn btn-success">{{ 'Activate'|t }}</button>
  </form>
  <form method="post">
    <input type="hidden" name="token_list" value="{{ token_list }}"/>
    <input type="hidden" name="action" value="deactivate"/>
    <input type="hidden" name="user_id" value="{{ user.id }}"/>
    <button type="submit" class="btn btn-danger">{{ 'Deactivate'|t }}</button>
  </form>
</div>
<br>
<br>
<img alt="VVF" src="./resources/images/owner.png" width="150"
  style="display: block; margin-left: auto; margin-right: auto;">
<br>
<br>
<table style="width:100%">
  <tr class="tHead">
    <th>{{ 'Name'|t }}</th>
    <th>{{ 'Available'|t }}</th>
    {% if user.full_viewer %}
    <th>{{ 'Driver'|t }}</th>
    <th>{{ 'Call'|t }}</th>
    <th>{{ 'Write'|t }}</th>
    <th>{{ 'Services'|t }}</th>
    <th>{{ 'Availability Minutes'|t }}</th>
    {# <th>{{ 'Other'|t }}</th> TODO: fix "Other" page #}
    {% endif %}
  </tr>
{% for row in query_results %}
  <tr class="tBody">
    {% if (date().timestamp-row.online_time) <= 30 %}
      <th><u>{{ username(row.id) }}</u></th>
    {% else %}
      <th>{{ username(row.id) }}</th>
    {% endif %}
    <th>
      {{ yesOrNo(row.available) }}
      {% set function = row.available ? "deactivate" : "activate" %}
      <form method="post">
        <input type="hidden" name="token_list" value="{{ token_list }}"/>
        <input type="hidden" name="action" value="{{ function }}"/>
        <input type="hidden" name="user_id" value="{{ row.id }}"/>
        <button type="submit">{{ 'Change'|t }}</button>
      </form>
    </th>
    {% if user.full_viewer %}
    <th>{{ yesOrNo(row.driver) }}</th>
    {% if row.phone_number %}
    <th><a href='tel:{{ row.phone_number }}'>Chiama</a></th>
    {% else %}
    <th></th>
    {% endif %}
    {% if row.phone_number %}
    <th><a href='https://api.whatsapp.com/send?phone={{ row.phone_number }}&text=ALLERTA IN CORSO.%20Mettiti%20in%20contatto%20con%20{{ username(row.id)|url_encode }}'>Manda un messaggio</a></th>
    {% else %}
    <th></th>
    {% endif %}
    <th>{{ row.services }}</th>
    <th>{{ row.availability_minutes }}</th>
    {# <th>{{ 'Other'|t }}</th> TODO: fix "Other" page #}
    {% endif %}
  </tr>
{% endfor %}
</table>

<br><br>
<p style="text-align: center;">
  <a href="edit_user.php?add" class="btn btn-success btn-small">{{ 'Add user'|t }}</a>
</p>
<br>
<br>
{% endblock %}