{% 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 %}
        <p>
          {% blocktrans %}
            To see the prior postings to this list, visit
            <a href="{{ hyperkitty_list_url }}">the 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:' %} <em>{{ subscribed_address }}</em>
            </p>
            {% url 'user_list_options' list.list_id as user_list_options_url %}
            <p>
              {% blocktrans %}
                You can manage your subscription on <a href="{{ user_list_options_url }}">your list options page</a>
              {% endblocktrans %}
            </p>
            <p>
                <form method="post" action="{% url 'list_unsubscribe' list.list_id %}">
                    {% csrf_token %}
                    <input type="hidden" name="email" value="{{ subscribed_address }}" />
                    <button type="submit" class="btn btn-danger">{% trans 'Unsubscribe' %}</button>
                </form>
            </p>
        {% 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 %}
