{% load static %}

{% include 'ping_me/partials/edit_popup.html' %}

{% if domain_list %}

{% include 'ping_me/partials/delete_popup.html' %}

<table>
    <thead>
        <tr>
            <th>Domain</th>
            <th>IP</th>
            <th>Description</th>
            <th>{{ current_month|date:"F Y"|capfirst }}</th>
            <th>{{ last_month|date:"F Y"|capfirst }}</th>
            {% if user.is_authenticated and user.is_staff %}
            <th>Bound to</th>
            <th>Action</th>
            {% endif %}
        </tr>
    </thead>
    <tbody>
        {% for domain in domain_list %}
        <tr>
            <td>
                {% if domain.last_ping and domain.last_ping.success %}
                <img src="{% static 'icons/accept_button.png' %}"
                    alt="OK" title="Online website">
                {% else %}
                <img src="{% static 'icons/exclamation.png' %}"
                    alt="NOK" title="Offline website">
                {% endif %}
                {{ domain.url }}
                <small>(<a href="http://{{ domain.url }}" target="_blank">see website</a>)</small>
            </td>
            <td>
            {% if domain.last_ping %}
                {{ domain.last_ping.address }}
            {% else %}
                No IP
            {% endif %}
            </td>
            <td>
                {{ domain.description }}
            </td>
            <td>
                {% include 'ping_me/partials/summary_percentage.html' with summary=domain.current_month_summary %}
            </td>
            <td>
                {% include 'ping_me/partials/summary_percentage.html' with summary=domain.last_month_summary %}
            </td>
            {% if user.is_authenticated and user.is_staff %}
            <td>
                {% if domain.user.email %}
                <a href="mailto:{{ domain.user.email }}">{{ domain.user.email }}</a>
                {% else %}
                {{ domain.user.username }} (no email)
                {% endif %}
            </td>
            <td>
                <button type="button" onclick="show_edit_popup({{ domain.id }})">
                    <img src="{% static 'icons/pencil.png' %}"
                        alt="Edit" title="Edit">
                </button>
                <button type="button" onclick="show_delete_popup({{ domain.id }})">
                    <img src="{% static 'icons/delete.png' %}"
                        alt="Delete" title="Delete">
                </button>
            </td>
            {% endif %}
        </tr>
        {% endfor %}
    </tbody>
</table>

{% else %}

    <p>You have no domain to show.</p>

{% endif %}

{% if user.is_authenticated and user.is_staff %}
<div class="text-center">
    <a href="#" onclick="show_edit_popup(0);return false;">Add a domain</a>
</div>
{% endif %}
