{% extends "layout.html" %}
{% block main %}

<div style="float: left;">
    <h1>Archive</h1>
</div>

<div style="float: right;">

    {% if results %}
    <form action="{{ url_for('.index') }}" method="post" class="search">
        <div>
            <label for="keyword">Search</label>
            <input type="text" id="keyword" name="keyword" value="">
            <button type="submit" id="submit">Submit</button>
        </div>
    </form>
    {% else %}
        <p>There are currently <b id="count">
            <img src="{{ url_for('static', filename='img/ajax-loader.gif') }}" style="width: 13px; height: 13px;"/></b> items in the archive
        </p>
        <script language="JavaScript">
            $('#count').load("{{ url_for('.count') }}");
        </script>
    {% endif %}

</div>
<div style="clear: both;"></div>


<!--
TODO: how to get this visible since count is now retrieved via ajax call ...

<div class="warning">
    <p>
        Your archive seems to be empty. To use archive feature you need to have task(s) with archive plugin enabled.
        Once archive plugin is enabled in a task it starts to add all new content from the task into the archive.
    </p>
</div>
-->


{% if results %}
    <div>
        <h2>Search results:</h2>

        <table class="search-results">
            <tr>
                <th style="width: 1em;">&nbsp</th>
                <th>Name</th>
                <th>Description</th>
                <th>Added</th>
                <th>Task</th>
            </tr>
            {% for archive in results %}
                <tr class="{{ loop.cycle('odd', 'even') }}">
                    <td>
                        <a href="inject/{{ archive.id }}">
                            <img src="{{ url_for('static', filename='img/fatcow-icons/16x16/add.png') }}"/>
                        </a>
                    </td>
                    <td><a href="{{ archive.url }}">{{ archive.title|wordwrap(width=60) }}</a></td>
                    <td>{{ archive.description|default('N/A', True)|wordwrap(width=40)|safe }}</td>
                    <td>{{ archive.added | pretty_age}}</td>
                    <td>{{ archive.task }}</td>
                </tr>
            {% endfor %}
        </table>
    </div>
{% else %}
    <div>
    <form action="{{ url_for('.index') }}" method="post" class="simple">
        <fieldset style="width:26em">
            <legend>Search from the archive</legend>
            <div>
                <label for="keyword">Words</label>
                <input type="text" id="keyword" name="keyword" value="{{ options }}" size="50">
            </div>
            <div class="buttons">
                <button type="submit">Submit</button>
            </div>
        </fieldset>
    </form>
    </div>
{% endif %}

{% endblock %}
