{% macro listPackages(packages, paginate, showAutoUpdateWarning, meta) %}
    <ul class="packages list-unstyled">
        {% for package in packages %}
            {% if package.id is numeric %}
                {% set packageUrl = path('view_package', { 'name' : package.name }) %}
            {% else %}
                {% set packageUrl = path('view_providers', { 'name' : package.name }) %}
            {% endif %}
            <li data-url="{{ packageUrl }}" class="row">
                <div class="col-xs-12 package-item">
                    <div class="row">
                        <div class="col-sm-9 col-lg-10">
                            {% if package.language is defined and package.language is not empty %}<p class="pull-right language">{{ package.language }}</p>{% endif %}
                            <h4 class="font-bold">
                                <a href="{{ packageUrl }}">{{ package.name }}</a>
                                {% if package.id is not numeric %}
                                    <small>(Virtual Package)</small>
                                {% endif %}
                                {% if showAutoUpdateWarning and not package.autoUpdated %}
                                    <small>(Not Auto-Updated)</small>
                                {% endif %}
                            </h4>
                            {% if package.description is defined and package.description %}
                                <p>{{ package.description }}</p>
                            {% endif %}
                            {% if package.abandoned is defined and package.abandoned %}
                                <p class="abandoned">
                                    <i class="glyphicon glyphicon-exclamation-sign"></i> Abandoned! {% if package.replacementPackage %}See <a href="{{ '://' in package.replacementPackage ? package.replacementPackage : path('view_package', {name: package.replacementPackage}) }}">{{ package.replacementPackage }}</a>{% endif %}
                                </p>
                            {% endif %}
                        </div>
                        <div class="col-sm-3 col-lg-2">
                            {% if meta %}
                                <p class="metadata">
                                    <span class="metadata-block"><i class="glyphicon glyphicon-arrow-down"></i> {{ meta.downloads[package.id]|default(0)|number_format(0, '.', '&#8201;')|raw }}</span>
                                    <span class="metadata-block"><i class="glyphicon glyphicon-star"></i> {{ meta.favers[package.id]|default(0)|number_format(0, '.', '&#8201;')|raw }}</span>
                                </p>
                            {% endif %}
                        </div>
                    </div>
                </div>
            </li>
        {% endfor %}

        {% if paginate is defined and paginate and packages.haveToPaginate() %}
            {{ pagerfanta(packages, 'twitter_bootstrap', {'proximity': 2}) }}
        {% endif %}
    </ul>
{% endmacro %}

{% macro listPackagesShort(packages, showVersion, showMoreUrl) %}
    <ul class="list-unstyled">
        {% for package in packages %}
            <li>
                <a href="{{ path('view_package', {'name' : package.name }) }}">{{ package.name }}{% if showVersion is defined and showVersion %}<strong>{{ package.version }}</strong>{% endif %}</a>
                {{ package.description|truncate(60) }}
            </li>
        {% endfor %}
        {% if showMoreUrl is defined and showMoreUrl %}
            <li><a href="{{ path('browse_popular') }}">See more...</a></li>
        {% endif %}
    </ul>
{% endmacro %}

{% macro packageLink(packageName, type) %}
    {%- if type == 'provide' and (packageName is existing_provider or packageName is existing_package) -%}
        <a href="{{ path('view_providers', { 'name': packageName }) }}">{{ packageName }}</a>
    {%- elseif packageName is existing_package -%}
        <a href="{{ path('view_package', { 'name': packageName }) }}">{{ packageName }}</a>
    {%- else -%}
        {{ packageName }}
    {%- endif -%}
{% endmacro %}
