{% extends "admin/base.html" %}

{% block messages %}
{% comment %} This is displayed elswhere {% endcomment %}
{% endblock messages %}

{% block extrahead %}
{{ block.super }}
<style>
    .message-error,
    .message-warning {
        font-weight: bold;
    }

    .message-error {
        color: #dc3545;
    }

    .message-warning {
        color: #ffc107;
    }
</style>
{% endblock %}

{% block content %}
<div id="content-main">
    {% if campaigns %}
    <h2>Importer Progress</h2>
    <ul>
        <table>
            <thead>
                <tr>
                    <th>Campaign Title</th>
                    <th></th>
                </tr>
            </thead>
            {% for campaign in campaigns %}
            <tr>
                <td>{{ campaign.title }}</td>
                <td><a href="?id={{ campaign.id}}">Check Progress</a></td>
            </tr>
            {% endfor %}
        </table>
    </ul>

    {% else %}

    {% if projects %}
    <h2>Projects</h2>
    <ul>
        <table>
            <thead>
                <tr>
                    <th>Project Title</th>
                    <th>Succesful</th>
                    <th>Incomplete</th>
                    <th>Failed</th>
                    <th></th>
                </tr>
            </thead>
            {% for project in projects %}
            <tr>
                <td>{{ project.title }}</td>
                <td>{{ project.succesful }}</td>
                <td><a
                        href="/admin/importer/importitemasset/?completed=null&import_item__job__project__id__exact={{ project.id}}&last_started=not-null">
                        {{ project.incomplete }}</a></td>
                <td><a
                        href="/admin/importer/importitemasset/?failed=not-null&import_item__job__project__id__exact={{ project.id}}&last_started=not-null">
                        {{ project.failure }}</a></td>
            </tr>
            {% endfor %}
        </table>
    </ul>

    <span>Total Assets: {{ totalassets }}</span>
    <span><a href="/admin/celery-review">All Campaigns</a></span>
    {% endif %}
    {% endif %}
    {% if messages %}
    <h4>Messages</h4>
    <ul>
        {% for message in messages %}
        <li
            class="message {% if message.level >= DEFAULT_MESSAGE_LEVELS.ERROR %}message-error{% elif message.level >= DEFAULT_MESSAGE_LEVELS.WARNING %}message-warning{% endif %}">
            {{ message }}</li>
        {% endfor %}
    </ul>
    {% endif %}
</div>
{% endblock content %}
