{#
#  OPTIONS
#  - displayContent: [short|long] default: short
#}
{% if w.goals|length > 0 %}
    <table class="obj-res-eval">
        <thead>
        <th class="obj"><h4 class="title_label">{{ 'accompanying_course_work.goal'|trans }}</h4></th>
        <th class="res"><h4 class="title_label">{{ 'accompanying_course_work.results'|trans }}</h4></th>
        </thead>
        <tbody>
        {% for g in w.goals %}
            <tr>
                <td class="obj">
                    <ul class="goal_title">
                        <li>{{ g.goal.title|localize_translatable_string }}</li>
                    </ul>
                </td>
                <td class="res">
                    {% if g.results|length == 0 %}
                        <p class="chill-no-data-statement">{{ 'accompanying_course_work.no_results'|trans }}</p>
                    {% else %}
                        <ul class="result_list">
                            {% for r in g.results %}
                                <li>{{ r.title|localize_translatable_string }}</li>
                            {% endfor %}
                        </ul>
                    {% endif %}
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
{% endif %}

{% if w.results|length > 0 %}

    <table class="obj-res-eval">
        <thead>
        <th class="obj"><h4 class="title_label">{{ 'accompanying_course_work.goal'|trans }}</h4></th>
        <th class="res"><h4 class="title_label">{{ 'accompanying_course_work.results'|trans }}</h4></th>
        </thead>
        <tbody>
        <tr>
            <td class="obj">
                <p class="chill-no-data-statement">{{ 'accompanying_course_work.results without objective'|trans }}</p>
            </td>
            <td class="res">
                <ul class="result_list">
                    {% for r in w.results %}
                        <li>{{ r.title|localize_translatable_string }}</li>
                    {% endfor %}
                </ul>
            </td>
        </tr>
        </tbody>
    </table>
{% endif %}


{% if w.accompanyingPeriodWorkEvaluations|length > 0 %}
    <table class="obj-res-eval">
        <thead>
        <th class="eval">
            <h4 class="title_label">{{ 'accompanying_course_work.evaluations'|trans }}</h4>
        </th>
        </thead>
        <tbody>
        {% if onlyone|default(false) %}
            {% for e in w.accompanyingPeriodWorkEvaluations %}
                {% if evalId is defined and evalId == e.id %}
                    <tr>
                    <td class="eval">
                    <ul class="eval_title">
                        <li>
                            {{ e.evaluation.title|localize_translatable_string }}
                            <ul class="columns">
                                <li>
                                    <span class="item-key">{{ 'accompanying_course_work.start_date'|trans ~ ' : ' }}</span>
                                    <b>{{ e.startDate|format_date('short') }}</b>
                                </li>

                                {% if e.endDate %}
                                    <li>
                                        <span
                                            class="item-key">{{ 'accompanying_course_work.end_date'|trans ~ ' : ' }}</span>
                                        <b>{{ e.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 %}

                                {% if e.maxDate %}
                                    <li>
                                        <span
                                            class="item-key">{{ 'accompanying_course_work.max_date'|trans ~ ' : ' }}</span>
                                        <b>{{ e.maxDate|format_date('short') }}</b>
                                    </li>
                                {% else %}
                                    {% if displayContent is defined and displayContent == 'long' %}
                                        <li>
                                        <span
                                            class="item-key">{{ 'accompanying_course_work.max_date'|trans ~ ' : ' }}</span>
                                            <span class="chill-no-data-statement">{{ 'Not given'|trans }}</span>
                                        </li>
                                    {% endif %}
                                {% endif %}

                                {% if e.warningInterval and e.warningInterval.d > 0 %}
                                    <li>
                                        {% set days = (e.warningInterval.d + e.warningInterval.m * 30) %}
                                        <span
                                            class="item-key">{{ 'accompanying_course_work.warning_interval'|trans ~ ' : ' }}</span>
                                        {{ 'accompanying_course_work.%days% days before max_date'|trans({'%days%': days }) }}
                                    </li>
                                {% else %}
                                    {% if displayContent is defined and displayContent == 'long' %}
                                        <li>
                                        <span
                                            class="item-key">{{ 'accompanying_course_work.warning_interval'|trans ~ ' : ' }}</span>
                                            <span class="chill-no-data-statement">{{ 'Not given'|trans }}</span>
                                        </li>
                                    {% endif %}
                                {% endif %}

                                {% if e.timeSpent is not null and e.timeSpent > 0 %}
                                    <li>
                                        {% set minutes = (e.timeSpent / 60) %}
                                        <span
                                            class="item-key">{{ 'accompanying_course_work.timeSpent'|trans ~ ' : ' }}</span> {{ 'duration.minute'|trans({ '{m}' : minutes }) }}
                                    </li>
                                {% elseif displayContent is defined and displayContent == 'long' %}
                                    <li>
                                        <span
                                            class="item-key">{{ 'accompanying_course_work.timeSpent'|trans ~ ' : ' }}</span>
                                        <span class="chill-no-data-statement">{{ 'Not given'|trans }}</span>
                                    </li>
                                {% endif %}
                            </ul>
                        </li>
                    </ul>
                {% endif %}


            {% endfor %}
            {% if recordAction is defined %}
                {{ recordAction }}
            {% endif %}
        {% else %}
            {% for e in w.accompanyingPeriodWorkEvaluations %}
                <tr>
                    <td class="eval">
                        <ul class="eval_title">
                            <li>
                                {{ e.evaluation.title|localize_translatable_string }}
                                <ul class="columns">
                                    <li>
                                        <span
                                            class="item-key">{{ 'accompanying_course_work.start_date'|trans ~ ' : ' }}</span>
                                        <b>{{ e.startDate|format_date('short') }}</b>
                                    </li>

                                    {% if e.endDate %}
                                        <li>
                                            <span
                                                class="item-key">{{ 'accompanying_course_work.end_date'|trans ~ ' : ' }}</span>
                                            <b>{{ e.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 %}

                                    {% if e.maxDate %}
                                        <li>
                                            <span
                                                class="item-key">{{ 'accompanying_course_work.max_date'|trans ~ ' : ' }}</span>
                                            <b>{{ e.maxDate|format_date('short') }}</b>
                                        </li>
                                    {% else %}
                                        {% if displayContent is defined and displayContent == 'long' %}
                                            <li>
                                                <span
                                                    class="item-key">{{ 'accompanying_course_work.max_date'|trans ~ ' : ' }}</span>
                                                <span class="chill-no-data-statement">{{ 'Not given'|trans }}</span>
                                            </li>
                                        {% endif %}
                                    {% endif %}

                                    {% if e.warningInterval and e.warningInterval.d > 0 %}
                                        <li>
                                            {% set days = (e.warningInterval.d + e.warningInterval.m * 30) %}
                                            <span
                                                class="item-key">{{ 'accompanying_course_work.warning_interval'|trans ~ ' : ' }}</span>
                                            {{ 'accompanying_course_work.%days% days before max_date'|trans({'%days%': days }) }}
                                        </li>
                                    {% else %}
                                        {% if displayContent is defined and displayContent == 'long' %}
                                            <li>
                                                <span
                                                    class="item-key">{{ 'accompanying_course_work.warning_interval'|trans ~ ' : ' }}</span>
                                                <span class="chill-no-data-statement">{{ 'Not given'|trans }}</span>
                                            </li>
                                        {% endif %}
                                    {% endif %}

                                    {% if e.timeSpent is not null and e.timeSpent > 0 %}
                                        <li>
                                            {% set totalHours = (e.timeSpent / 3600)|round(0, 'floor') %}
                                            {% set totalMinutes = ((e.timeSpent % 3600) / 60)|round(0, 'floor') %}

                                            <span class="item-key">{{ 'accompanying_course_work.timeSpent'|trans ~ ' : ' }}</span>

                                            {% if totalHours >= 8 %}
                                                {% set days = (totalHours / 8)|round(0, 'floor') %}
                                                {% set remainingHours = totalHours % 8 %}

                                                {% if days > 0 %}
                                                    {{ 'duration.day'|trans({ '{d}' : days }) }}
                                                {% endif %}
                                                {% if remainingHours > 0 %}
                                                    {{ 'duration.hour'|trans({ '{h}' : remainingHours }) }}
                                                {% endif %}
                                            {% else %}
                                                {% if totalHours > 0 %}
                                                    {{ 'duration.hour'|trans({ '{h}' : totalHours }) }}
                                                {% endif %}
                                                {% if totalMinutes > 0 %}
                                                    {{ 'duration.minute'|trans({ '{m}' : totalMinutes }) }}
                                                {% endif %}
                                            {% endif %}
                                        </li>
                                    {% elseif displayContent is defined and displayContent == 'long' %}
                                        <li>
                                            <span
                                                class="item-key">{{ 'accompanying_course_work.timeSpent'|trans ~ ' : ' }}</span>
                                            <span class="chill-no-data-statement">{{ 'Not given'|trans }}</span>
                                        </li>
                                    {% endif %}
                                </ul>
                            </li>
                        </ul>
                        {% if recordAction is defined %}
                            {{ recordAction }}
                        {% endif %}

                        {% if displayContent is defined and displayContent == 'long' %}

                            {% if e.comment is not empty %}
                                <blockquote class="chill-user-quote">{{ e.comment }}</blockquote>
                            {% endif %}

                            {% import "@ChillDocStore/Macro/macro.html.twig" as m %}
                            {% import "@ChillDocStore/Macro/macro_mimeicon.html.twig" as mm %}
                            {% if e.documents|length > 0 %}
                                <table class="table table-hover align-middle mt-4 mx-auto">
                                    {% for d in e.documents %}
                                        <tr>
                                            <td class="border-0">{{ d.title }}</td>
                                            <td class="border-0">{{ mm.mimeIcon(d.storedObject.type) }}</td>
                                            <td class="border-0 text-end">
                                                {% if accompanyingCourse.hasUser and accompanyingCourse.user is not same as(app.user) %}
                                                    <button id="btnGroupNotifyButtons" type="button" class="btn btn-sm 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\\AccompanyingPeriodWorkEvaluationDocument',
                                                                   'entityId': d.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\\AccompanyingPeriodWorkEvaluationDocument',
                                                                   'entityId': d.id}) }}">{{ 'notification.Notify any'|trans }}</a>
                                                        </li>
                                                    </ul>
                                                {% else %}
                                                    <a class="btn btn-notify btn-sm"
                                                       title="{{ 'notification.Notify'|trans }}"
                                                       href="{{ chill_path_add_return_path('chill_main_notification_create', {
                                                           'entityClass': 'Chill\\PersonBundle\\Entity\\AccompanyingPeriod\\AccompanyingPeriodWorkEvaluationDocument',
                                                           'entityId': d.id }) }}"></a>
                                                {% endif %}

                                                {{ d.storedObject|chill_document_button_group(d.title, is_granted('CHILL_MAIN_ACCOMPANYING_PERIOD_WORK_UPDATE', w), {'small': true}) }}
                                            </td>
                                        </tr>
                                    {% endfor %}
                                </table>
                            {% else %}
                                <span class="chill-no-data-statement">{{ 'No document found'|trans }}</span>
                            {% endif %}


                        {% endif %}
                    </td>
                </tr>
            {% endfor %}
        {% endif %}
        </tbody>
    </table>
{% endif %}
