{% extends "postorius/base.html" %}
{% load i18n %}
{% load bootstrap_tags %}
{% load nav_helpers %}
{% load markdown %}

{% block head_title %}
{% trans 'Info' %} | {{ list.fqdn_listname }} - {{ block.super }}
{% endblock %}

{% block content %}

    {% list_nav 'list_summary' 'msgid:title:list_summary' %}

    <p>{{ list.settings.description }}</p>
    {% if list.settings.info %}
        {% autoescape off %}
          {% markdown_value list.settings.info %}
        {% endautoescape %}
    {% endif %}
    <p>{% trans 'To contact the list owners, use the following email address:' %} <em>{{ list.settings.owner_address }}</em></p>

    {# Archives #}
    {% if hyperkitty_enabled %}
      {% if not public_archive and not user.is_authenticated %}
        <p>
          {% trans 'You have to login to visit the archives of this list.' %}
        </p>
      {% else %}
        {% url 'hk_list_overview' list.fqdn_listname as hyperkitty_list_url %}
        <h2>{% trans 'Archives' %}</h2>
        <p>
          {% blocktrans %}
            <a class="btn btn-primary" href="{{ hyperkitty_list_url }}">Archives</a>
          {% endblocktrans %}
        </p>
      {% endif %}
    {% endif %}

    <hr />

    {# Subscription #}
    {% if user.is_authenticated %}
        {% if user_subscribed %}
            <h2>{% trans 'Subscription / Unsubscription' %}</h2>
            <p>
              {% trans 'You are subscribed to this list with the following address:' %}
              {% if subscribed_preferred %}
                  <em>{% trans 'Primary Address' %} ({{ subscribed_address }})</em>
              {% else %}
                  <em>{{ subscribed_address }}</em>
              {% endif %}
            </p>
            {% url 'user_list_options' list.list_id as user_list_options_url %}
              <a class="btn btn-primary" href="{{ user_list_options_url }}">{% trans 'Manage Subscription' %}</a>
            <p></p>
              <form method="post" action="{% url 'list_unsubscribe' list.list_id %}" class="form-inline">
                    {% csrf_token %}
                    <input type="hidden" name="email" value="{{ subscribed_address }}" />
                    <button type="submit" class="btn btn-danger">{% trans 'Unsubscribe' %}</button>
                </form>
        {% elif user_request_pending %}
            <h4>{% trans "You have a subscription request pending. If you don't hear back soon, please contact the list owners." %}</h4>
        {% else %}
            <h2>{% trans 'Subscribe to this list' %}</h2>
            <p>
              {% blocktrans with address=list.settings.join_address %}
                  To subscribe you can send an email with 'subscribe' in the subject to
                  <a href="mailto:{{ address }}?subject=Subscribe">{{ address }}</a>
                  or use the form below:
              {% endblocktrans %}
            </p>
            <form action="{% url 'list_subscribe' list.list_id %}" method="post" class="form-horizontal">
                {% bootstrap_form_horizontal subscribe_form 2 8 'Subscribe' %}
            </form>
        {% endif %}
    {% else %}
      <div>
        <h2>{% trans 'Subscription / Unsubscription' %}</h2>
        <p>{% blocktrans %}
        To subscribe or unsubscribe from this list, please log in first.
        If you have not previously logged in, you may need to set up an account
        with the appropriate email address.
        {% endblocktrans %}</p>
        <p><a href="{% url LOGIN_URL %}?next={{ next|default:request.path|urlencode }}" class="btn btn-primary">{% trans 'Log In' %}</a></p>
      </div>
      <hr />
      <div>
        <p>
        {% blocktrans %}
        You can also subscribe without creating an account.
        If you wish to do so, please use the form below.
        {% endblocktrans%}
        </p>
        <form action="{% url 'list_anonymous_subscribe' list.list_id %}"
              method="post" class="form-horizontal">
          {% bootstrap_form_horizontal anonymous_subscription_form 2 8 'Subscribe' %}
        </form>
      </div>
    {% endif %}

    {# List metrics #}
    {% if user.is_authenticated %}
        {% if user.is_list_owner or user.is_superuser %}
            <hr />
            <h3>{% trans 'List metrics' %}</h3>
            <dl class="row">
              <dt class="col-2">{% trans 'Created at' %}</dt><dd class="col-2">{{ list.settings.created_at }}</dd>
              <div class="w-100"></div>
              <dt class="col-2">{% trans 'Last post at' %}</dt><dd class="col-2">{{ list.settings.last_post_at }}</dd>
              <div class="w-100"></div>
              <dt class="col-2">{% trans 'Digest last sent at' %}</dt><dd class="col-2">{{ list.settings.digest_last_sent_at }}</dd>
              <div class="w-100"></div>
              <dt class="col-2">{% trans 'Volume' %}</dt><dd class="col-2">{{ list.settings.volume }}</dd>
            </dl>
        {% endif %}
    {% endif %}
{% endblock %}
