{% extends "app.html" %}
{% comment %}
# SPDX-License-Identifier: AGPL-3.0-or-later
{% endcomment %}

{% load bootstrap %}
{% load i18n %}
{% load static %}

{% block page_head %}
  <link type="text/css" rel="stylesheet"
        href="{% static 'letsencrypt/letsencrypt.css' %}"/>
{% endblock %}

{% block configuration %}

  <h3>{% trans "Status" %}</h3>

  {% if status.domains %}
    <div class="table-responsive">
      <table class="table">
        <thead>
          <tr>
            <th>{% trans "Domain" %}</th>
            <th>{% trans "Certificate Status" %}</th>
            <th>{% trans "Website Security" %}</th>
            <th>{% trans "Actions" %}</th>
          </tr>
        </thead>
        <tbody>
          {% for domain, domain_status in status.domains.items %}
            <tr>
              <td>{{ domain }}</td>
              <td>
                {% if domain_status.certificate_available and domain_status.validity == "valid" %}
                  <span class="badge text-bg-success">
                    {% blocktrans trimmed with expiry_date=domain_status.expiry_date %}
                      Valid, expires on {{ expiry_date }}
                    {% endblocktrans %}
                  </span>
                {% elif domain_status.certificate_available and not domain_status.validity == "valid" %}
                  <span class="badge text-bg-warning">
                    {% if "revoked" in domain_status.validity %}
                      {% blocktrans trimmed %}
                        Revoked
                      {% endblocktrans %}
                    {% elif "expired" in domain_status.validity %}
                      {% blocktrans trimmed with expiry_date=domain_status.expiry_date %}
                        Expired on {{ expiry_date }}
                      {% endblocktrans %}
                    {% elif "test" in domain_status.validity %}
                      {% blocktrans trimmed %}
                        Invalid test certificate
                      {% endblocktrans %}
                    {% else %}
                      {% blocktrans trimmed with reason=domain_status.validity %}
                        Invalid ({{ reason }})
                      {% endblocktrans %}
                    {% endif %}
                  </span>
                {% else %}
                  <span class="badge text-bg-warning">
                    {% trans "No certificate" %}
                  </span>
                {% endif %}
              </td>
              <td>
                {% if domain_status.web_enabled %}
                  <span class="badge text-bg-success">{% trans "Enabled" %}</span>
                {% else %}
                  <span class="badge text-bg-warning">{% trans "Disabled" %}</span>
                {% endif %}
              </td>
              <td class="operations">
                {% if domain_status.certificate_available %}
                  <form class="form" method="post"
                        action="{% url 'letsencrypt:re-obtain' domain %}">
                    {% csrf_token %}
                    <button class="btn btn-sm btn-default" type="submit">
                      {% trans "Re-obtain" %}</button>
                  </form>
                  <form class="form" method="post"
                        action="{% url 'letsencrypt:delete' domain %}">
                    {% csrf_token %}
                    <button class="btn btn-sm btn-default" type="submit">
                      {% trans "Delete" %}</button>
                  </form>
                  {% if "revoked" not in domain_status.validity %}
                    <form class="form" method="post"
                          action="{% url 'letsencrypt:revoke' domain %}">
                      {% csrf_token %}
                      <button class="btn btn-sm btn-default" type="submit">
                        {% trans "Revoke" %}</button>
                    </form>
                  {% endif %}
                {% else %}
                  <form class="form" method="post"
                        action="{% url 'letsencrypt:obtain' domain %}">
                    {% csrf_token %}
                    <button class="btn btn-sm btn-primary" type="submit">
                      {% trans "Obtain" %}</button>
                  </form>
                {% endif %}
              </td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  {% else %}
    {% url 'names:index' as names_url %}
    {% blocktrans trimmed %}
      No domains have been configured. <a href="{{ names_url }}">Configure
      domains</a> to be able to obtain certificates for them.
    {% endblocktrans %}
  {% endif %}
{% endblock %}
