{% load i18n %}
{% load static %}

{% load unicms_contexts %}
{% load unicms_templates %}

{% settings_value "CMS_PUBLICATION_LIST_PREFIX_PATH" as page_news_suffix %}

{% if publications %}
<div class="row d-lg-flex">

    {% for item in publications %}

        {% if forloop.first %}
        {% if publications.count == 1 %}
        <div class="col-12">
        {% else %}
        <div class="col-12 col-lg-8">
        {% endif %}
            <div class="card-wrapper card-space">
                <div class="card card-bg no-after">
                    <div class="card-body ps-lg-0">
                        <div class="row h-100">
                            {% if item.publication.image_url %}
                            <div class="col-12 col-lg-6">
                                <div class="etichetta d-lg-none">
                                    {% for cat in item.publication.categories %}
                                    <span class="badge rounded-pill badge-grey-unical my-1 py-2 px-4 me-1">
                                        <a class="no-color" href="{% call obj=item method='get_url_list' category_name=cat.name %}">
                                            <b>{{ cat.name }}</b>
                                        </a>
                                    </span>
                                    {% endfor %}
                                </div>

                                <div class="img-responsive-wrapper mb-3 mx-n4 d-lg-none">
                                    <div class="img-responsive img-responsive-panoramic">
                                        <figure class="img-wrapper">
                                          <a href="{{ item.url }}">
                                            <img src="{{ item.publication.image_url }}"
                                                 title="{{ item.publication.image_title }}"
                                                 alt="{{ item.publication.image_description }}"
                                                 loading="lazy">
                                          </a>
                                        </figure>
                                    </div>
                                </div>
                                <div class="img-responsive-wrapper d-none d-lg-block h-100">
                                    <div class="img-responsive img-responsive-panoramic h-100">
                                        <figure class="img-wrapper">
                                          <a href="{{ item.url }}" class="d-none d-lg-block h-100">
                                                <img src="{{ item.publication.image_url }}"
                                                     title="{{ item.publication.image_title }}"
                                                     alt="{{ item.publication.image_description }}"
                                                     class="h-100"
                                                     loading="lazy">
                                            </a>
                                        </figure>
                                    </div>
                                </div>
                            </div>

                            {% endif %}
                            <div class="col-12 col-lg-6 ps-lg-4">

                                <div class="etichetta d-none d-lg-block">
                                    {% for cat in item.publication.categories %}
                                    <span class="badge rounded-pill badge-grey-unical my-1 py-2 px-4 me-1">
                                        <a class="no-color" href="{% call obj=item method='get_url_list' category_name=cat.name %}">
                                            <b>{{ cat.name }}</b>
                                        </a>
                                    </span>
                                    {% endfor %}
                                </div>

                                 <div class="category-top">
                                    <span>{% trans "Published" %}: {{ item.date_start | date:"d/m/Y, H:i" }}</span>
                                    {% include "includes/edit_news.html" with item=item %}
                                </div>

                                <a class="no-color" href="{{ item.url }}">
                                    <h4 class="card-title">
                                        {{ item.publication.title }}
                                    </h4>
                                </a>
                                {% if item.publication.subheading %}
                                <p class="card-text">
                                    {{ item.publication.subheading }}
                                </p>
                                {% endif %}

                                {% include "includes/social_share.html" with share_title=item.publication.title share_url=request.get_host|add:item.url %}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        {% comment %}
        {% elif forloop.counter0 == 1 %}
        <div class="col-12 col-lg-4">
            <div class="card-wrapper card-space">
                <div class="card card-bg no-after">
                    <div class="card-body">
                        <div class="etichetta">
                            {% for cat in item.publication.categories %}
                            <span class="badge rounded-pill badge-grey-unical my-1 py-2 px-4 me-1">
                                <a class="no-color" href="{% call obj=item method='get_url_list' category_name=cat.name %}">
                                    <b>{{ cat.name }}</b>
                                </a>
                            </span>
                            {% endfor %}
                        </div>

                         <div class="category-top">
                            <span>{% trans "Published" %}: {{ item.date_start | date:"d/m/Y, H:i" }}</span>
                            {% include "includes/edit_news.html" with item=item %}
                        </div>

                        <h4 class="card-title">
                            <a href="{{ item.url }}" class="no-color">
                                {{ item.publication.title }}
                            </a>
                        </h4>

                        {% include "includes/social_share.html" with share_title=item.publication.title share_url=request.get_host|add:item.url %}
                    </div>
                </div>
            </div>
        </div>
        {% endcomment %}
        {% else %}

        <div class="col-12 col-lg-4">
            <!--start card-->
            <div class="card-wrapper card-space">
                <div class="card card-bg no-after">
                    <div class="card-body">
                        <div class="etichetta">
                            {% for cat in item.publication.categories %}
                                <span class="badge rounded-pill badge-grey-unical my-1 py-2 px-4 me-1">
                                    <a class="no-color" href="{% call obj=item method='get_url_list' category_name=cat.name %}">
                                        <b>{{ cat.name }}</b>
                                    </a>
                                </span>
                            {% endfor %}
                        </div>
                        {% if item.publication.image_url %}
                        <div class="img-responsive-wrapper mb-3 mx-n4">
                            <div class="img-responsive img-responsive-panoramic">
                                <figure class="img-wrapper">
                                  <a href="{{ item.url }}">
                                    <img src="{{ item.publication.image_url }}"
                                         title="{{ item.publication.image_title }}"
                                         alt="{{ item.publication.image_description }}"
                                         loading="lazy">
                                  </a>
                                </figure>
                            </div>
                        </div>
                        {% endif %}
                        <div class="category-top">
                            <span>{% trans "Published" %}: {{ item.date_start | date:"d/m/Y, H:i" }}</span>
                            {% include "includes/edit_news.html" with item=item %}
                        </div>

                        <h4 class="card-title">
                            <a href="{{ item.url }}" class="no-color">
                                {{ item.publication.title }}
                            </a>
                        </h4>
                        {% if not item.publication.image_url %}
                        <p class="card-text">
                            {{ item.publication.subheading}}
                        </p>
                        {% endif %}

                        {% include "includes/social_share.html" with share_title=item.publication.title share_url=request.get_host|add:item.url %}
                    </div>
                </div>
            </div>
            <!--end card-->
        </div>
        {% endif %}

    {% endfor %}

</div>

<p class="mt-3 ms-2">
    <a href="{{ page_news_suffix }}" class="no-color">
        <span class="text-black fw-bold">
            <svg class="icon me-2">
                <use xlink:href="{% static '/svg/sprites.svg' %}#it-arrow-right-circle"></use>
            </svg>
            {% trans "Go to all news" %}
        </span>
    </a>
</p>
{% endif %}
