{#
#  OPTIONS
#  - itemBlocClass: [uniq|colored|extended]
#  - displayContent: [short|long] default: short
#  - displayAction: [true|false] default: false
#  - displayFontSmall: [true|false] default: false
#}
<div
    class="item-bloc{% if displayContent is defined %} {{ displayContent }}{% endif %}{% if itemBlocClass is defined %} {{ itemBlocClass }}{% endif %}">

    <div class="item-row">
        <h2 class="badge-title">
            <span class="title_label"></span>
            <span class="title_action">{{ w.socialAction|chill_entity_render_string }}

                <ul class="small_in_title columns mt-1">
                    <li>
                        <span class="item-key">{{ 'accompanying_course_work.start_date'|trans ~ ' : ' }}</span>
                        <b>{{ w.startDate|format_date('short') }}</b>
                    </li>
                    {% if w.endDate %}
                        <li>
                            <span class="item-key">{{ 'accompanying_course_work.end_date'|trans ~ ' : ' }}</span>
                            <b>{{ w.endDate|format_date('short') }}</b>
                        </li>
                    {% else %}
                        {% if displayContent is defined and displayContent == 'long' %}
                            <li>
                                <span class="item-key">{{ 'accompanying_course_work.end_date'|trans ~ ' : ' }}</span>
                                <span class="chill-no-data-statement">{{ 'Not given'|trans }}</span>
                            </li>
                        {% endif %}
                    {% endif %}
                </ul>

            </span>
        </h2>
    </div>

    <div class="item-row separator">
        <div class="wrap-list">

            {%- if w.persons -%}{# Usagers du parcours #}
                <div class="wl-row">
                    <div class="wl-col title">
                        <h3>{{ 'Persons in accompanying course'|trans }}</h3>
                    </div>
                    <div class="wl-col list">
                        {% for p in w.persons %}
                            <span class="wl-item">
                                {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
                                    action: 'show', displayBadge: true,
                                    targetEntity: { name: 'person', id: p.id },
                                    buttonText: p|chill_entity_render_string,
                                    isDead: p.deathdate is not null
                                } %}
                            </span>
                        {% endfor %}
                    </div>
                </div>
            {% endif %}

            {%- if w.handlingThierParty -%}{# Tiers traitant #}
                <div class="wl-row">
                    <div class="wl-col title">
                        <h3>{{ 'Thirdparty handling'|trans }}</h3>
                    </div>
                    <div class="wl-col list">
                        <span class="wl-item">
                            {% include '@ChillMain/OnTheFly/_insert_vue_onthefly.html.twig' with {
                                action: 'show', displayBadge: true,
                                targetEntity: { name: 'thirdparty', id: w.handlingThierParty.id },
                                buttonText: w.handlingThierParty|chill_entity_render_string
                            } %}
                        </span>
                    </div>
                </div>
            {% endif %}

            <div class="wl-row">{# Agents traitants #}
                <div class="wl-col title">
                    <h3>{%- if w.referrers|length > 1 -%}{{ 'Referrers'|trans }}{% else %}{{ 'Referrer2'|trans }}{% endif %}</h3>
                </div>
                <div class="wl-col list">
                    {%- if w.referrers|length > 0 -%}
                        {% for r in w.referrersHistoryCurrent %}
                            <span class="wl-item">
                                <span class="badge-user">{{ r.user|chill_entity_render_box({'at_date': r.startDate}) }}</span>
                                {%- if not loop.last %}, {% endif %}
                            </span>
                        {% endfor %}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'No referrer'|trans }}</span>
                    {% endif %}
                </div>
            </div>

            {%- if w.socialAction.issue -%}{# Problématique sociale #}
                <div class="wl-row">
                    <div class="wl-col title">
                        <h3>{{ 'Social issue'|trans }}</h3>
                    </div>
                    <div class="wl-col list">
                        <p class="wl-item social-issues">
                            {{ w.socialAction.issue|chill_entity_render_box }}
                        </p>
                    </div>
                </div>
            {% endif %}

        </div>
    </div>

    {% if displayContent is not defined or displayContent == 'short' %}
        <div
            class="item-row column{% if displayFontSmall is defined and displayFontSmall == true %} smallfont{% endif %}">
            {% include '@ChillPerson/AccompanyingCourseWork/_objectifs_results_evaluations.html.twig' with {
                'displayContent': displayContent,
                'onlyone': false
            } %}
        </div>
    {% endif %}

    {% if displayContent is not defined or displayContent == 'short' %}
        <div class="item-row separator">

            {% import '@ChillPerson/AccompanyingCourseWork/_macros.html.twig' as macro %}

            <div class="item-col item-meta">
                {{ macro.metadata(w) }}
            </div>

            {% if displayAction is defined and displayAction == true %}
                <ul class="item-col record_actions">
                    <li>{{ macro.workflowButton(w) }}</li>
                    {% if displayNotification is defined and displayNotification == true %}
                        <li>
                            <div class="d-grid gap-2 {% if accompanyingCourse.hasUser and accompanyingCourse.user is not same as(app.user) %}btn-group{% endif %}" {% if accompanyingCourse.hasUser and accompanyingCourse.user is not same as(app.user) %}role="group"{% endif %}>
                                {% if accompanyingCourse.hasUser and accompanyingCourse.user is not same as(app.user) %}
                                    <button id="btnGroupNotifyButtons" type="button" class="btn btn-notify dropdown-toggle" title="{{ 'notification.Notify'|trans }}" data-bs-toggle="dropdown" aria-expanded="false">
                                    </button>
                                    <ul class="dropdown-menu" aria-labelledby="btnGroupNotifyButtons">
                                        <li>
                                            <a class="dropdown-item" href="{{ chill_path_add_return_path('chill_main_notification_create', {'entityClass': 'Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWork', 'entityId': w.id, 'tos': [accompanyingCourse.user.id]}) }}">{{ 'notification.Notify referrer'|trans }}</a>
                                        </li>
                                        <li>
                                            <a class="dropdown-item" href="{{ chill_path_add_return_path('chill_main_notification_create', {'entityClass': 'Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWork', 'entityId': w.id}) }}">{{ 'notification.Notify any'|trans }}</a>
                                        </li>
                                    </ul>
                                {% else %}
                                    <a class="btn btn-notify" title="{{ 'notification.Notify'|trans }}" href="{{ chill_path_add_return_path('chill_main_notification_create', {'entityClass': 'Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWork', 'entityId': w.id}) }}">
                                    </a>
                                {% endif %}
                            </div>
                        </li>
                    {% endif %}
                    <li>
                        <a class="btn btn-show" title="{{ 'Show'|trans }}"
                           href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_show', {'id': w.id }) }}"
                        ></a>
                    </li>
                    {% if is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE', w) %}
                        <li>
                            <a class="btn btn-edit" title="{{ 'Edit'|trans }}"
                               href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_edit', { 'id': w.id }) }}"
                            ></a>
                        </li>
                    {% endif %}
                    {% if is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_DELETE', w) %}
                        <li>
                            <a class="btn btn-delete" title="{{ 'Delete'|trans }}"
                               href="{{ path('chill_person_accompanying_period_work_delete', { 'id': w.id } ) }}"
                            ></a>
                        </li>
                    {% endif %}
                </ul>
            {% endif %}
        </div>
    {% endif %}

</div>

{#
#   This is for 'long' version of content
#   Note: this include is wrapped in a flex-table container.
#   We start by closing the flex-table so we can add more.
#   At the end we leave the last flex-table open, as it will be closed in the container.
#}
{% if displayContent is defined and displayContent == 'long' %}
</div>

{% if w.results|length > 0 or w.goals|length > 0 or w.accompanyingPeriodWorkEvaluations|length > 0 %}
    <h2 class="chill-blue">{{ 'Dispositifs' }}</h2>

    <div class="flex-table">{# new flex-table wrapper #}
        <div
            class="item-bloc colored{% if displayContent is defined %} {{ displayContent }}{% endif %}{% if itemBlocClass is defined %} {{ itemBlocClass }}{% endif %}">
            {% include '@ChillPerson/AccompanyingCourseWork/_objectifs_results_evaluations.html.twig' with {
                'displayContent': displayContent,
                'onlyone' : false
            } %}
        </div>
    </div>
{% endif %}

<h2 class="chill-blue">{{ 'Comments'|trans }}</h2>

<div class="flex-table">
    <div
        class="item-bloc no-altern{% if displayContent is defined %} {{ displayContent }}{% endif %}{% if itemBlocClass is defined %} {{ itemBlocClass }}{% endif %}">
        <h3 class="chill-beige">Public</h3>
        {% if w.note is not empty %}
            <blockquote class="chill-user-quote">
                {{ w.note|chill_markdown_to_html }}
            </blockquote>
        {% else %}
            <span class="chill-no-data-statement">{{ 'No comment associated'|trans }}</span>
        {% endif %}
    </div>
    {% if w.privateComment.hasCommentForUser(app.user) %}
        <div
            class="item-bloc no-altern{% if displayContent is defined %} {{ displayContent }}{% endif %}{% if itemBlocClass is defined %} {{ itemBlocClass }}{% endif %}">
            <h3 class="chill-beige">Privé</h3>
            <blockquote class="chill-user-quote private-quote">
                {{ w.privateComment.commentForUser(app.user)|chill_markdown_to_html }}
            </blockquote>
        </div>
    {% endif %}
    {# Here flex-table stay open ! read above #}

    {% endif %}
