{% set paths_base = "../.." %}
{% set bodyClasses = "single single-tender" %}

{% set post = post_type.tenders.items[currentPost] %}

{% extends "base.twig" %}

{% block breadcrumbs %}

    {% set breadcrumbs_block = 
        {
            "post_type": "tenders",
            "show_terms": false,
            "current_id": currentPost,
            "classes": "breadcrumbs--spacing-2"
        }
    %}
    {% include '../blocks/breadcrumbs.twig' with {'block': breadcrumbs_block } %}

{% endblock %}

{% block content %}

    <div class="grid-container">

        <div>
            <div class="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>
            <div class="spacing-5">
                <span class="status status--{{post.status.class}}"><span></span>{{post.status.label}}</span>
            </div>

            <div class="block-container block-grid-list spacing-5">
                <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 class="block-paragraph block-paragraph--1col">
                {{post.content}}
            </div>

            {% if post.files_list %}
                <div class="spacing-5">
                    {% set tender_files = {
                        "key": "files-list",
                        "classes": "",
                        "content": {
                            "label": "Materiali",
                            "items": post.files_list
                        }
                    } %}
                    {% include '../blocks/files-list.twig' with {'block': tender_files } %}
                </div>
            {% endif %}

            {% if post.status.class != 'expired' and post.status.class != 'completed' %}
                <div>
                    {% set tender_application_cta = {
                        "key": "link",
                        "url": "https://www.google.com",
                        "classes": "",
                        "links_size": null,
                        "content": {
                            "name": "Compila la domanda",
                            "external_name": "Pica"
                        }
                    } %}
                    {% include '../blocks/link.twig' with {'block': tender_application_cta } %}
                </div>
            {% endif %}            

        </div>
        
    </div>


{% endblock %}