{% extends "/pyshop/layout.html" %}

{% block subnav %}
    <h2>{% trans %}Available Packages ({{package_count}}){% endtrans %}</h2>
{% endblock %}


{% block main %}

<form class="filter" method="GET">
    <input type="text" id="classifier" class="filter-input"
           name="classifier.added" value=""/>
    <button name="form.submitted">
        {% trans %} filter {% endtrans %}
    </button>
    <ul class="selected-classifiers">
        {% for c in filter.classifiers %}
            <li>
                <input type="checkbox" id="classifier_{{loop.index}}"
                       name="classifiers" checked="checked" value="{{c.id}}"/>
                <label for="classifier_{{loop.index}}">{{c.name}}</label>
            </li>
        {% endfor %}
        <li>
            <input type="checkbox" id="source_local" name="local_only" value="1"
                    {%if filter.local_only%}checked="checked"{% endif %}/>
            <label for="source_local">
                {% trans %}locals only{% endtrans %}
            </label>
        </li>
    </ul>
</form>

<table>
    <colgroup>
        <col class="label">
        <col class="version">
        <col class="download">
        <col class="source">
    </colgroup>
    <tr>
        <th>{% trans %} package {% endtrans %}</th>
        <th>{% trans %} last version {% endtrans %}</th>
        <th>{% trans %} # downloads {% endtrans %}</th>
        <th>{% trans %} source {% endtrans %}</th>
    </tr>

    {% for pkg in packages %}
        <tr>
            <td>
                <a href="{{ route_url('show_package', package_name=pkg.name) }}">
                    {{ pkg.name }}
                </a>
            </td>
            <td class="num">{{ pkg.versions[0] }}</td>
            <td class="num">{{ pkg.downloads }}</td>
            <td class="num">
                {% if pkg.local %}
                    {% trans %} local {% endtrans %}
                {% else %}
                    {% trans %} mirror {% endtrans %}
                {% endif %}
            </td>
        </tr>
    {% endfor %}
</table>

<script>
    $(function() {
        var classifiers = [
        {% for c in classifiers %}
            '{{c.name}}',
        {% endfor %}
        ];
        $( "#classifier" ).autocomplete({
            source: classifiers
        });
    });
</script>
{% endblock %}
