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

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

{% block extra_content %}
  <h3>{% trans "Domains" %}</h3>

  <div class="btn-toolbar">
    <a href="{% url 'dynamicdns:domain-add' %}" class="btn btn-primary"
       role="button" title="{% trans 'Add Domain' %}">
      <span class="fa fa-plus" aria-hidden="true"></span>
      {% trans 'Add Domain' %}
    </a>
  </div>

  {% if domains_status %}
    <div class="table-responsive domains-status">
      <table class="table">
        <thead>
          <tr>
            <th>{% trans "Domain" %}</th>
            <th>{% trans "Last update" %}</th>
            <th>{% trans "Result" %}</th>
            <th>{% trans "IP Address" %}</th>
            <th>{% trans "Actions" %}</th>
          </tr>
        </thead>
        <tbody>
          {% for domain in domains_status.values %}
            <tr>
              <td class="domain-name">
                <a href="{% url 'dynamicdns:domain-edit' domain.domain %}"
                   title="{% blocktrans trimmed with domain=domain.domain %}
                            Edit domain {{ domain }}
                          {% endblocktrans %}">
                  {{ domain.domain }}
                </a>
              </td>
              <td>
                {% if domain.timestamp %}
                  {{ domain.timestamp|timesince }}
                {% else %}
                  {% trans "Not yet" %}
                {% endif %}
              </td>
              <td>
                {% if domain.result %}
                  <span class="badge text-bg-success">
                    {% trans "Success" %}
                  </span>
                {% elif not domain.timestamp %}
                  -
                {% else %}
                  <span class="badge text-bg-warning">
                    {% trans "Failed" %}
                  </span>
                {% endif %}
                {% if domain.error_message %}
                  ({{ domain.error_message }})
                {% elif domain.error_code %}
                  ({{ domain.error_code }})
                {% endif %}
              </td>
              <td>{{ domain.ip_address|default_if_none:'-' }}</td>
              <td>
                <a href="{% url 'dynamicdns:domain-edit' domain.domain %}"
                   class="btn btn-default btn-sm domain-edit" role="button"
                   title="{% blocktrans trimmed with domain=domain.domain %}
                            Edit domain {{ domain }}
                         {% endblocktrans %}">
                  <span class="fa fa-pencil-square-o" aria-hidden="true"></span>
                </a>
                <a href="{% url 'dynamicdns:domain-delete' domain.domain %}"
                   class="btn btn-default btn-sm domain-delete" role="button"
                   title="{% blocktrans trimmed with domain=domain.main %}
                          Delete domain {{ domain }}
                          {% endblocktrans %}">
                  <span class="fa fa-trash" aria-hidden="true"></span>
                </a>
              </td>
            </tr>
          {% endfor %}
        </tbody>
      </table>
    </div>
  {% else %}
    <p>{% trans "No domains configured." %}</p>
  {% endif %}
{% endblock %}
