{% extends "misago/admin/generic/list.html" %}
{% load i18n misago_admin_form misago_capture %}


{% block page-actions %}
<div class="col-auto page-action">
  <a href="{% url 'misago:admin:settings:agreements:new' %}" class="btn btn-primary btn-sm">
    <span class="fa fa-plus-circle"></span>
    {% trans "New agreement" %}
  </a>
</div>
{% endblock %}


{% block table-header %}
<th style="width: 1px;">&nbsp;</th>
<th>{% trans "Agreement" %}</th>
<th style="width: 1px;">&nbsp;</th>
<th style="width: 180px;">{% trans "Type" %}</th>
<th style="width: 250px;">{% trans "Created" %}</th>
<th style="width: 250px;">{% trans "Modified" %}</th>
<th style="width: 1px;">&nbsp;</th>
{% endblock table-header %}


{% block table-row %}
<td class="pr-0">
  {% if item.is_active %}
    <a href="{{ item.get_absolute_url }}" class="btn btn-light btn-sm">
      <span class="fas fa-external-link-alt"></span>
    </a>
  {% endif %}
</td>
<td class="pr-0 small">
  <a href="{% url 'misago:admin:settings:agreements:edit' pk=item.pk %}" class="item-name">
    {{ item.get_final_title }}
  </a>
</td>
<td class="badges-list">
  {% if item.is_active %}
    <span class="badge badge-success" data-tooltip="top" title="{% trans 'Users are required to accept this agreement to use the site' %}">
      {% trans "Active" %}
    </span>
  {% endif %}
</td>
<td class="small">
  {{ item.get_type_display }}
</td>
<td class="small">
  {% capture trimmed as created_on %}
    <abbr data-timestamp="{{ item.created_on.isoformat }}" data-format="LL"></abbr>
  {% endcapture %}
  {% capture trimmed as created_by %}
    {% if item.created_by %}
      <a href="{{ item.created_by.get_absolute_url }}" class="item-title">{{ item.created_by }}</a>
    {% else %}
      <span class="item-title">{{ item.created_by_name }}</span>
    {% endif %}
  {% endcapture %}
  {% blocktrans trimmed with created_on=created_on|safe created_by=created_by|safe %}
    {{ created_on }} by {{ created_by }}
  {% endblocktrans %}
</td>
<td class="small">
  {% if item.last_modified_on %}
    {% capture trimmed as last_modified_on %}
      <abbr data-timestamp="{{ item.last_modified_on.isoformat }}" data-format="LL">
        {{ item.last_modified_on }}
      </abbr>
    {% endcapture %}
    {% capture trimmed as last_modified_by %}
      {% if item.last_modified_by %}
        <a href="{{ item.last_modified_by.get_absolute_url }}" class="item-title">{{ item.last_modified_by }}</a>
      {% else %}
        <span class="item-title">{{ item.last_modified_by }}</span>
      {% endif %}
    {% endcapture %}
    {% blocktrans trimmed with last_modified_on=last_modified_on|safe last_modified_by=last_modified_by|safe %}
      {{ last_modified_on }} by {{ last_modified_by }}
    {% endblocktrans %}
  {% else %}
    <em>{% trans "never" %}</em>
  {% endif %}
</td>
<td>
  <div class="dropdown">
    <button class="btn btn-light btn-sm dropdown-toggle" type="button" id="item-optioms-{{ item.pk }}" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
      <i class="fas fa-ellipsis-h"></i>
    </button>
    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="item-optioms-{{ item.pk }}">
      {% if not item.is_active %}
        <form action="{% url 'misago:admin:settings:agreements:set-as-active' pk=item.pk %}" method="post" data-set-as-active-confirmation="true">
          {% csrf_token %}
          <button class="dropdown-item">
            {% trans "Set as active" %}
          </button>
        </form>
      {% else %}
        <form action="{% url 'misago:admin:settings:agreements:disable' pk=item.pk %}" method="post" data-disable-confirmation="true">
          {% csrf_token %}
          <button class="dropdown-item">
            {% trans "Disable agreement" %}
          </button>
        </form>
      {% endif %}
      <a class="dropdown-item" href="{% url 'misago:admin:settings:agreements:edit' pk=item.pk %}">
        {% trans "Edit agreement" %}
      </a>
      <form action="{% url 'misago:admin:settings:agreements:delete' pk=item.pk %}" method="post" data-delete-confirmation="true">
        {% csrf_token %}
        <button class="dropdown-item">
          {% trans "Remove agreement" %}
        </button>
      </form>
    </div>
  </div>
</td>
{% endblock %}


{% block blankslate %}
<td colspan="8">
  {% if active_filters %}
    {% trans "No agreements matching criteria exist." %}
  {% else %}
    {% trans "No agreements are set." %}
  {% endif %}
</td>
{% endblock blankslate %}


{% block javascripts %}
{{ block.super }}
<script type="text/javascript">
  window.misago.initConfirmation(
    "[data-set-as-active-confirmation]",
    "{% trans 'Are you sure you want to set this agreement as active for its type?' %}"
  )
  window.misago.initConfirmation(
    "[data-disable-confirmation]",
    "{% trans 'Are you sure you want to disable this agreement?' %}"
  )
  window.misago.initConfirmation(
    "[data-delete-confirmation]",
    "{% trans 'Are you sure you want to remove this agreement?' %}"
  )
</script>
{% endblock %}


{% block filters-modal-body %}
<div class="row">
  <div class="col">
    {% form_row filter_form.type %}
  </div>
</div>
<div class="row">
  <div class="col">
    {% form_row filter_form.content %}
  </div>
</div>
{% endblock filters-modal-body %}
