{% extends "../../layout/archive.twig" %}

{% set type = "tenders" %}

{% block archive_col_1 %}
    {% set breadcrumbs_block = 
        {
            "post_type": "archive",
            "type": post_type,
            "object": "tenders"
        }
    %}
    {% include '../../blocks/breadcrumbs.twig' with {'block': breadcrumbs_block } %}
{% endblock %}

{% block archive_col_2 %}
    <div class="posts-archive-description">
        <p>{{post_type[~type~].description}}</p>
    </div>
{% endblock %}

{% block filters %}

    <div>
        {% set archive_filters = {
            "key": "filters",
            "classes": "",
            "content": {
                "items": [
                    {
                        "type": "term",
                        "post_type": type,
                        "id": 0
                    },
                    {
                        "type": "term",
                        "post_type": type,
                        "id": 1
                    },
                    {
                        "type": "term",
                        "post_type": type,
                        "id": 2
                    }
                ],
                "has_search": true
            }
            } %}
        {% include "../../blocks/filters.twig" with {"block": archive_filters } %}
    </div>

{% endblock %}

{% block posts %}

    {% for post in post_type.tenders.items %}
        <div class="post-row{% if post.status %} post-row--{{post.status.class}}{% endif %}">
            <div class="post-row__inner">

                <div>
                    <div class="post-row-date tender-date">
                        {% if post.status.class == 'expired' or post.status.class == 'completed' %}Scaduto{% endif %}

                        {% if post.date is iterable %}
                            <div>
                                <span>Prorogato al {{post.date[1]|date('d.m.Y, H:s')}}</span>
                                <span>Scadenza {{post.date[0]|date('d.m.Y, H:s')}}</span>
                            </div>
                        {% else %}
                            <span>Scadenza {{post.date|date('d.m.Y, H:s')}}</span>    
                        {% endif %}
                        
                    </div>
                    <span class="status status--{{post.status.class}}"><span></span>{{post.status.label}}</span>
                </div>

                <div class="post-row-content">

                    <a href="{{post.url}}" class="post-row-title">{{post.title}}</a>

                    <div class="block-container block-grid-list">
                        <div class="block-grid-list__inner">

                            {% for id in post.terms|slice(0,1) %}
                                {% set parent = id[0] %}
                                {% set terms = id[1] %}
                                {% set taxonomy = taxonomies.tenders.terms[parent] %}
                                <div>
                                    <p>{{taxonomy.name}}</p>
                                    <p>
                                    {% for term in terms %}
                                        {% set term = taxonomies.tenders.terms[parent].items[term] %}
                                        <span>{{term.name}}</span>{% if not loop.last %}, {% endif %}
                                    {% endfor %}
                                    </p>
                                </div>
                            {% endfor %}
                            <div>
                                <p>Posti disponibili</p>
                                <p>{{post.seats}}</p>
                            </div>
                            {% for id in post.terms|slice(1) %}
                                {% set parent = id[0] %}
                                {% set terms = id[1] %}
                                {% set taxonomy = taxonomies.tenders.terms[parent] %}
                                <div>
                                    <p>{{taxonomy.name}}</p>
                                    <p>
                                    {% for term in terms %}
                                        {% set term = taxonomies.tenders.terms[parent].items[term] %}
                                        <span>{{term.name}}</span>{% if not loop.last %}, {% endif %}
                                    {% endfor %}
                                    </p>
                                </div>
                            {% endfor %}
                            {% for item in post.info %}
                                <div>
                                    <p>{{item.label}}</p>
                                    <p>{{item.text}}</p>
                                </div>
                            {% endfor %}

                        </div>
                    </div>

                </div>
            </div>
            <div class="post-row__footer">
                {% if post.status.class == 'open' %}
                    {% set tender_links = {
                        "key": "links-list",
                        "classes": "block-links-list--2cols",
                        "links_size": "sm",
                        "content": {
                            "list": [
                                {
                                    "name": "Vedi i materiali",
                                    "url": post.url,
                                },
                                {
                                    "name": "Compila la domanda",
                                    "url": "https://www.google.com",
                                    "external_name": "Pica"
                                }
                            ]
                        }
                    } %}
                {% elseif post.status.class == 'completed' %}
                    {% set tender_links = {
                        "key": "links-list",
                        "classes": "",
                        "links_size": "sm",
                        "content": {
                            "list": [
                                {
                                    "name": "Vedi i materiali e l'esito",
                                    "url": "#",
                                }
                            ]
                        }
                    } %}
                {% else %}
                    {% set tender_links = {
                        "key": "links-list",
                        "classes": "",
                        "links_size": "sm",
                        "content": {
                            "list": [
                                {
                                    "name": "Vedi i materiali",
                                    "url": "#",
                                }
                            ]
                        }
                    } %}
                {% endif %}
            
                {% include "../../blocks/links-list.twig" with {'block': tender_links } %}
            </div>
        </div>
    {% endfor %}

{% endblock %}