{% load hc_extras static %}
<table
    id="checks-table"
    class="table {% if rw %}rw{% endif%}"
    data-list-url="{% url 'hc-checks' project.code %}"
    data-status-url="{% url 'hc-status' project.code %}">
    <tr>
        <th></th>
        <th class="th-name">
            {% if sort == "name" %}
            <a href="?sort=-name" data-toggle="tooltip" class="sort-name">
                Name<span class="ic-asc"></span>
            </a>
            {% elif sort == "-name" %}
            <a href="?sort=created" data-toggle="tooltip" class="sort-name">
                Name<span class="ic-desc"></span>
            </a>
            {% else %}
            <a href="?sort=name" data-toggle="tooltip" class="default sort-name">
                Name
            </a>
            {% endif %}
        </th>
        <th class="hidden-xs hidden-sm">
            <span class="visible-lg">Ping URL</span>
            <span class="visible-md">Code</span>
        </th>
        <th class="th-integrations hidden-xs">Integrations</th>
        <th class="th-period hidden-xs">
            Period <br />
            <span class="checks-subline">Grace</span>
        </th>
        <th class="th-last-ping hidden-xs">
            {% if sort == "last_ping" %}
            <a href="?sort=created" data-toggle="tooltip" class="sort-last-ping">
                Last Ping<span class="ic-desc"></span>
            </a>
            {% elif sort == "-last_ping" %}
            <a href="?sort=last_ping" data-toggle="tooltip" class="sort-last-ping">
                Last Ping<span class="ic-asc"></span>
            </a>
            {% else %}
            <a href="?sort=-last_ping" data-toggle="tooltip" class="default sort-last-ping">
                Last Ping</span>
            </a>
            {% endif %}
            {% if show_last_duration %}
            <br />
            <span class="checks-subline">Last Duration</span>
            {% endif %}
        </th>
        <th></th>
    </tr>
    {% for check in checks %}
    <tr
        id="{{ check.code }}"
        class="checks-row"
        data-url="{{ check.url }}"
        data-email="{{ check.email }}"
        {% if check in hidden_checks %}style="display: none"{% endif %}>

        <td class="indicator-cell">
            <span class="status ic-{{ check.get_status }}" data-toggle="tooltip"></span>
            <div class="spinner {% if check.last_start %}started{% endif %}">
                <div class="d1"></div>
                <div class="d2"></div>
                <div class="d3"></div>
            </div>
        </td>
        <td>
            <div data-name="{{ check.name }}"
                 data-tags="{{ check.tags }}"
                 data-desc="{{ check.desc }}"
                 class="my-checks-name {% if not check.name %}unnamed{% endif %}">
                <div>{{ check.name|default:"unnamed"|break_underscore }}</div>
                {% for tag in check.tags_list %}
                <span class="label label-tag">{{ tag }}</span>
                {% endfor %}
            </div>
        </td>
        <td class="url-cell hidden-xs hidden-sm">
            <span class="my-checks-url">
                <span class="base hidden-md">{{ ping_endpoint }}</span>{{ check.code }}
            </span>
            <button
                class="copy-link hidden-sm"
                data-clipboard-text="{{ check.url }}">
                copy
            </button>
        </td>
        <td class="integrations-cell hidden-xs">
            {% if channels|length <= 10 %}
                <div class="integrations">
                {% spaceless %}
                {% for channel in channels %}
                    <span class="ic-{{ channel.kind }}{% if channel in check.channel_set.all %}{% else %} off{% endif %}"></span>
                {% endfor %}
                {% endspaceless %}
                </div>
            {% else %}
                {{ check.channel_set.all|length }} of {{ channels|length }}
            {% endif %}
        </td>
        <td class="timeout-cell hidden-xs">
            <div
                data-kind="{{ check.kind }}"
                data-timeout="{{ check.timeout.total_seconds }}"
                data-grace="{{ check.grace.total_seconds }}"
                data-schedule="{{ check.schedule }}"
                data-tz="{{ check.tz }}"
                class="timeout-grace">
                {% if check.kind == "simple" %}
                    {{ check.timeout|hc_duration }}
                    <br />
                {% elif check.kind == "cron" %}
                    <div class="cron-expression">{{ check.schedule }}</div>
                {% endif %}
                <span class="checks-subline">
                {{ check.grace|hc_duration }}
                </span>
            </div>
        </td>
        <td class="hidden-xs">
            <div id="lpd-{{ check.code }}" class="last-ping">
                {% include "front/last_ping_cell.html" with check=check %}
            </div>
        </td>
        <td class="actions">
            {% if rw %}
            <button class="btn btn-default pause" type="button">
                <span class="ic-paused" />
            </button>
            {% endif %}

            <button title="Show Details" class="btn btn-default show-log" type="button">
                <span class="ic-dots" />
            </button>
        </td>
    </tr>
    {% endfor %}

</table>

{% for channel in channels %}
<div
    id="ch-{{ forloop.counter0}}"
    data-code="{{ channel.code }}"
    data-title="{{ channel }}">
</div>
{% endfor %}
