{% include setlang.html %}

{% assign limititems = include.limit | default: 4 %}
{% assign items = site.data.crawler.software | sample: 4 %}

{% assign title = include.title %}
{% assign captiontitle = include.captiontitle %}
{% assign captionurl = include.captionurl %}
{% assign withimages = include.withimages | default: false %}

<section class="home-listing-items crop source-{{include.source}} {{include.additionalclass}}">
    <div class="container">
        <div class="d-flex align-items-baseline titlewrapper mb-3 mb-md-5">
            <h1>{{title}}</h1>
            {% if captiontitle!=nil%}
            <a href="{{captionurl}}" class="ml-auto more">{{captiontitle}} &rarr;</a>
            {% endif %}
        </div>
        <div class="row row-eq-height">
            {% for item in items limit: limititems %}

            {% assign description = item.publiccode.description[active_lang]
            | default: item.publiccode.description.en
            | default: item.publiccode.description.it %}

            {% assign sw_name = description.localisedName | default: item.publiccode.name %}

            {% assign sw_url = '/' | append: active_lang | append: '/software/' | append: item.slug | downcase %}

            <div class="col-md {% if withimages!=true %}px-3{%endif%}">
              {% if withimages == true %}

              {% if item.publiccode.it.riuso.codiceIPA != nil %}
                {% assign category = "software_reuse" %}
                {% assign icon = "it-software" %}
                {% assign fallback = "/assets/images/cover_softwareriuso.png" %}
              {% else %}
                {% assign category = "software_open" %}
                {% assign fallback = "it-open-source" %}
                {% assign fallback = "/assets/images/cover_software_opensource.png" %}
              {% endif %}

              {% assign first_screenshot = description.screenshots | first %}

              <catalogue-item
                class="h-100"
                id="{{  item.id }}"
                name="{{ sw_name }}"
                description="{{ description.shortDescription | escape }}"
                url="{{ sw_url }}"
                icon="{{ icon }}"
                category="{{ category }}"
                logo="{{ item.publiccode.logo | default: first_screenshot }}"
                fallback="{{ fallback }}"
              ></catalogue-item>

              {% endif %}
            </div>
            {% endfor %}
        </div>
        {% if include.viewalltitle %}
        <div class="row pb-3 mt-3 mb-3 mt-md-5">
            <a class="btn btn-primary mx-auto" href="{{include.viewallurl}}">{{include.viewalltitle}}</a>
        </div>
        {% endif %}

    </div>

</section>
