{% extends "postorius/base.html" %}
{% load i18n %}
{% load pagination %}

{% block head_title %}
{% trans 'List Index' %} - {{ block.super }}
{% endblock %}

{% block content %}

    <div class="page-header">
        <h1>{% trans 'Mailing Lists' %}</h1>
    </div>

    <div class="row">
    {% if user.is_authenticated %}
        <div class="dropdown page-left col-md-4">
          <button class="btn btn-outline-secondary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
            Filter by Role
            <span class="caret"></span>
          </button>
          <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
            <li><a href="?role=owner" class="dropdown-item">Owner</a></li>
            <li><a href="?role=moderator" class="dropdown-item">Moderator</a></li>
            <li><a href="?role=member" class="dropdown-item">Member</a></li>
            <li><a href="?role=nonmember" class="dropdown-item">Non-member</a></li>
            <li><a href="?all-lists" class="dropdown-item">All</a></li>
          </ul>
        </div>
        <div class="col-md-4">
          {% if role  %}
             <h4> Role {{ role | title }} </h4>
          {% endif %}
        </div>
    {% endif %}
    {% if user.is_superuser %}
      <div class="col-md-4">
        <p class="text-right">
            {% if domain_count < 1 %}
                <a class="btn btn-success" href="{% url 'domain_new' %}">{% trans 'Create New Domain' %}</a>
            {% else %}
                <a class="btn btn-success" href="{% url 'list_new' %}">{% trans 'Create New List' %}</a>
            {% endif %}
        </p>
      </div>
    {% endif %}
    </div>

    {% if lists|length > 0 %}
        <div class="table-responsive">
            <table class="table table-bordered table-striped">
                <thead>
                    <tr>
                        <th>{% trans 'List name' %}</th>
                        <th>{% trans 'Post address' %}</th>
                        <th>{% trans 'Description' %}</th>
                    </tr>
                </thead>
                <tbody>
                    {% for list in lists %}
                        <tr>
                            <td>
                                <a href="{% url 'list_summary' list_id=list.list_id %}">{{ list.display_name }}</a>
                                {% if check_advertised %}
                                  {% if user.is_superuser and not list.settings.advertised %}
                                    ({% trans 'unadvertised' %}*)
                                  {% endif %}
                                {% endif %}
                            </td>
                            <td>{{ list.fqdn_listname }}</td>
                            <td>{{ list.description }}</td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
        {% if not all_lists and not role %}
            <small>* {% trans 'Only lists that you are owner, moderator or subscriber for are shown here.' %} Click to <a href="?all-lists"> see all lists</a>.</small>
            <br/>
        {% endif %}
        {% if user.is_superuser %}
            <small>* {% trans 'Only admins see unadvertised lists in the list index.' %}</small>
        {% endif %}
        {% if not user.is_authenticated or "all-lists" in request.GET %}
            {% paginator lists %}
        {% endif %}
    {% else %}
        <p>{% trans 'There are currently no mailing lists.' %}</p>
    {% endif %}

{% endblock content %}
