{% extends '@ChillMain/layout.html.twig' %}

{% block title "Liste de parcours à répartir" %}

{% block js %}
    {{ encore_entry_script_tags('mod_set_referrer') }}
{% endblock %}

{% block css %}
    {{ encore_entry_link_tags('mod_set_referrer') }}
{% endblock %}

{% macro period_meta(period) %}
    {% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_UPDATE', period) %}
        <div class="item-col item-meta">
            {% set job_id = null %}
            {% if period.job is not null %}
                {% set job_id = period.job.id %}
            {% endif %}
            <span
                data-set-referrer-app="data-set-referrer-app"
                data-set-referrer-accompanying-period-id="{{ period.id }}"
                data-set-referrer-job-id="{{ job_id }}"
            ></span>
        </div>
    {% endif %}
{% endmacro %}

{% macro period_actions(period) %}
    {% if is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', period) %}
    <li>
       <a href="{{ chill_path_add_return_path('chill_person_accompanying_course_index', {'accompanying_period_id': period.id}) }}" class="btn btn-show"></a>
    </li>
    {% endif %}
{% endmacro %}

{% import _self as m %}

{% block content %}
    <div class="col-10">
        <h1>{{ block('title') }}</h1>

        {{ form_start(form) }}
        <div class="row">
            <div class="col-md-4">
                {{ form_label(form.locations ) }}
                {{ form_widget(form.locations, {'attr': {'class': 'select2'}}) }}
            </div>
            <div class="col-md-4">
                {{ form_label(form.jobs) }}
                {{ form_widget(form.jobs, {'attr': {'class': 'select2'}}) }}
            </div>
            <div class="col-md-4">
                {{ form_label(form.services) }}
                {{ form_widget(form.services, {'attr': {'class': 'select2'}}) }}
            </div>
        </div>

        <ul class="record_actions">
            <li>
                <button type="submit" class="btn btn-save change-icon">
                    <i class="fa fa-filter"></i> Filtrer
                </button>
            </li>
        </ul>

        {{ form_end(form) }}


        {% if periods|length == 0 %}
            <p class="chill-no-data-statement">Aucun parcours à désigner, ou droits insuffisants pour les afficher</p>
        {% else %}

            <p><span class="badge rounded-pill bg-primary">{{ paginator.totalItems }}</span> parcours à attribuer (calculé ce jour à {{ null|format_time('medium') }})</p>

            <div class="flex-table">
                {% for period in periods %}
                    {% include '@ChillPerson/AccompanyingPeriod/_list_item.html.twig' with {'period': period,
                        'recordAction': m.period_actions(period), 'itemMeta': m.period_meta(period), 'show_address': true } %}
                {% endfor %}
            </div>
        {% endif %}

        {{ chill_pagination(paginator) }}

    </div>
{% endblock %}

