{% load i18n %}
{% load translations %}
{% load icons %}
{% load crispy_forms_tags %}

<tr>
  {% if not user.is_bot %}
  <td>
    <a href="{{ user.get_absolute_url }}">{{ user.username }}</a>
  </td>
  {% endif %}
  <td>
    {{ user.full_name }}
  </td>
  {% if not user.is_bot and can_edit_user %}
    <td>{{ user.email }}</td>
  {% endif %}
  <td>
    {% if user.is_bot %}
        {{ user.date_expires|naturaltime }}
    {% else %}
      {% if user.last_login %}
        {{ user.last_login|naturaltime }}
      {% else %}
        {% trans "Not yet signed in" %}
      {% endif %}
    {% endif %}
  </td>
  <td>
    {% for group in user.project_groups %}
      <span class="badge">{{ group }}</span>
    {% endfor %}
  </td>
  <td>
    <a href="#" data-toggle="modal" data-target="#edit_user_{{ user.id }}" class="btn btn-link btn-xs" title="{% trans "Edit" %}">
      {% icon 'pencil.svg' %}
    </a>
    <a href="#" data-toggle="modal" data-target="#delete_user_{{ user.id }}" class="btn btn-link btn-xs red" title="{% trans "Remove" %}">
      {% icon 'delete.svg' %}
    </a>
    <form action="{% url "delete-user" project=object.slug %}" method="post" class="inlineform">
      {% csrf_token %}
      <input type="hidden" name="user" value="{{ user.username }}" />
      <div class="modal fade" tabindex="-1" role="dialog" id="delete_user_{{ user.id }}">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="{% trans "Close" %}"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title">{% trans "Are you absolutely sure?" %}</h4>
            </div>
            <div class="modal-body">
              {% blocktrans with user=user.username %}This will remove <b>{{ user }}</b> access to this project.{% endblocktrans %}
            </div>
            <div class="modal-footer">
              <input type="submit" class="btn btn-danger" value="{% trans "Remove" %}" />
            </div>
          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
      </div><!-- /.modal -->
    </form>

    <form action="{% url "set-groups" project=object.slug %}" method="post" class="inlineform">
      {% csrf_token %}
      <div class="modal fade" tabindex="-1" role="dialog" id="edit_user_{{ user.id }}">
        <div class="modal-dialog" role="document">
          <div class="modal-content">
            <div class="modal-header">
              <button type="button" class="close" data-dismiss="modal" aria-label="{% trans "Close" %}"><span aria-hidden="true">&times;</span></button>
              <h4 class="modal-title">{% blocktrans with username=user.username %}Edit team membership for {{ username }}{% endblocktrans %}</h4>
            </div>
            <div class="modal-body">
              {{ user.group_edit_form| crispy }}
            </div>
            <div class="modal-footer">
              <input type="submit" class="btn btn-primary" value="{% trans "Save" %}" />
            </div>
          </div><!-- /.modal-content -->
        </div><!-- /.modal-dialog -->
      </div><!-- /.modal -->
    </form>


    {% if not user.last_login and not user.is_bot %}
      <form action="{% url "resend_invitation" project=object.slug %}" method="post" class="inlineform">
        {% csrf_token %}
        <input type="hidden" name="user" value="{{ user.username }}" />
        <button type="submit" class="btn btn-link btn-xs" title="{% trans "Resend invitation" %}">
        {% icon 'refresh.svg' %}
        </button>
      </form>
    {% endif %}
  </td>
</tr>
