{% extends '@ChillPerson/AccompanyingCourse/layout.html.twig' %}

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

{% block title 'accompanying_course_work.Show accompanying course work'|trans %}

{% block css %}
    {{ parent() }}
    {{ encore_entry_link_tags('mod_entity_workflow_pick') }}
    {{ encore_entry_link_tags('mod_document_action_buttons_group') }}
{% endblock %}

{% block js %}
    {{ parent() }}
    {{ encore_entry_script_tags('mod_entity_workflow_pick') }}
    {{ encore_entry_script_tags('mod_document_action_buttons_group') }}
{% endblock %}

{% block content %}
    <div class="accompanying-course-work">
        <h1>{{ block('title') }}</h1>

        <div class="flex-table mt-4">
            {% include '@ChillPerson/AccompanyingCourseWork/_item.html.twig' with {
                'w': work,
                'displayAction': false,
                'displayContent': 'long',
                'itemBlocClass': 'uniq extended',
            } %}
            <div class="p-3 mt-3">{{ macro.metadata(work, false) }}</div>
        </div>

        <div class="notification notification-list">
            {% set more = [] %}
            {% for e in work.accompanyingPeriodWorkEvaluations %}
                 {% for d in e.documents %}
                     {% set more = more|merge([{'relatedEntityClass': 'Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument', 'relatedEntityId': d.id}]) %}
                 {% endfor %}
            {% endfor %}
            {% set notifications =  chill_list_notifications('Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWork', work.id, more) %}
            {% if notifications is not empty %}
                {{ notifications|raw }}
            {% endif %}
        </div>

        <ul class="record_actions sticky-form-buttons">
            <li class="cancel">
                <a href="{{ path('chill_person_accompanying_period_work_list', { 'id': accompanyingCourse.id }) }}"
                   class="btn btn-cancel">{{ 'Back to the list'|trans }}</a>
            </li>
            <li>{{ macro.workflowButton(work) }}</li>
            <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': work.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': work.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': work.id}) }}">
                        </a>
                    {% endif %}
                </div>
            </li>
            {% if work.accompanyingPeriod.getWorks|length > 1 %}
            <li>
                <a class="btn btn-misc" href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_assign_duplicate', { 'id': work.id }) }}">
                    <i class="bi bi-chevron-contract"></i>
                    {{ 'Merge'|trans }}
                </a>
            </li>
            {% endif %}
            {% if is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE', work) %}
                <li>
                    <a class="btn btn-edit"
                       href="{{ chill_path_add_return_path('chill_person_accompanying_period_work_edit', { 'id': work.id }) }}"
                    >{{ 'Edit'|trans }}</a>
                </li>
            {% endif %}
            {% if is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_DELETE', work) %}
                <li>
                    <a class="btn btn-delete"
                       href="{{ path('chill_person_accompanying_period_work_delete', { 'id': work.id } ) }}"
                        title = "{{ 'Delete'|trans }}"
                    ></a>
                </li>
            {% endif %}
        </ul>

    </div>
{% endblock %}

{% block block_post_menu %}
    <div class="post-menu pt-4"></div>
{% endblock %}
