{%- set t = entity.type -%}
{% set userId = app.user.id %}
{%- import "@ChillDocStore/Macro/macro.html.twig" as m -%}

<h1>{{ "Activity"|trans }}</h1>

<div class="flex-table">
    <div class="item-bloc">

        <div class="item-row">
            <div class="wrap-list">
                <div class="wl-row">
                    <div class="wl-col title">
                        {% if entity.date %}
                            <p class="date-label">
                                {{ entity.date|format_date('short') }}
                            </p>
                        {% endif %}
                    </div>
                    <div class="wl-col list">
                        <h2 class="badge-title">
                            <span class="title_label"></span>
                            <span class="title_action">
                                {{ entity.type.name | localize_translatable_string }}
                                {% if entity.emergency %}
                                    <span class="badge bg-danger rounded-pill fs-6 float-end">{{ 'Emergency'|trans|upper }}</span>
                                {% endif %}
                            </span>
                        </h2>
                    </div>
                </div>
            </div>
        </div>

        <div class="item-row separator">
            <dl class="chill_view_data">
                {%- if entity.user is not null %}
                    <dt class="inline">{{ 'Referrer'|trans|capitalize }}</dt>
                    <dd>
                        <span class="badge-user">{{ entity.user|chill_entity_render_box({'at_date': entity.date}) }}</span>
                    </dd>
                {% endif %}

                {%- if entity.scope -%}
                    <dt class="inline">{{ 'Scope'|trans }}</dt>
                    <dd>
                        <span class="scope">{{ entity.scope.name|localize_translatable_string }}</span>
                    </dd>
                {% endif %}

                {% if t.socialIssuesVisible %}
                    <dt class="inline">{{ 'Social issues'|trans }}</dt>
                    <dd>
                        {% if entity.socialIssues|length == 0 %}
                            <p class="chill-no-data-statement">{{ 'No social issues associated'|trans }}</p>
                        {% else %}
                            {% for si in entity.socialIssues %}{{ si|chill_entity_render_box }}{% endfor %}
                        {% endif %}
                    </dd>
                {% endif %}

                {% if t.socialActionsVisible %}
                    <dt class="inline">{{ 'Social actions'|trans }}</dt>
                    <dd>
                        {% if entity.socialActions|length == 0 %}
                            <span class="chill-no-data-statement">{{ 'No social actions associated'|trans }}</span>
                        {% else %}
                            {% for sa in entity.socialActions %}{{ sa|chill_entity_render_box }}{% endfor %}
                        {% endif %}
                    </dd>
                {% endif %}

                {% if t.reasonsVisible %}
                    <dt class="inline">{{ 'Reasons'|trans }}</dt>
                    <dd>
                        {%- if entity.reasons is empty -%}
                            <span class="chill-no-data-statement">{{ 'No reason associated'|trans }}</span>
                        {%- else -%}
                            {% for r in entity.reasons %}{{ r|chill_entity_render_box }}{% endfor %}
                        {%- endif -%}
                    </dd>
                {% endif %}
            </dl>
        </div>

    </div>
</div>

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

{% include '@ChillActivity/Activity/concernedGroups.html.twig' with {
    'context': context,
    'render': 'bloc',
    'badge_person': true
} %}

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

<div class="flex-table">
    <div class="item-bloc">

        <dl class="chill_view_data">
            <dt class="inline">{{ 'Date'|trans }}</dt>
            <dd>{{ entity.date|format_date('long') }}</dd>

            {% if t.locationVisible %}
                <dt class="inline">{{ 'Activity location'|trans }}</dt>
                <dd>
                    {% if entity.location is not null %}
                        <p>
                            {{ entity.location.name }}
                            <span>({{ entity.location.locationType.title|localize_translatable_string }})</span>
                        </p>
                        <div class="ms-3">{{ entity.location.address|chill_entity_render_box }}</div>
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'No address given'|trans }}</span>
                    {% endif %}
                </dd>
            {% endif %}

            {% if t.durationTimeVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
                <dt class="inline">{{ 'Duration Time'|trans }}</dt>
                <dd>
                    {% if entity.durationTime is not null %}
                        {{ entity.durationTime|date('H:i') }}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'None'|trans|capitalize }}</span>
                    {% endif %}
                </dd>
            {% endif %}

            {% if t.travelTimeVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
                <dt class="inline">{{ 'Travel time'|trans }}</dt>
                <dd>
                    {% if entity.travelTime is not null %}
                        {{ entity.travelTime|date('H:i') }}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'None'|trans|capitalize }}</span>
                    {% endif %}
                </dd>
            {% endif %}

            {% if t.commentVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
                <dt class="inline">{{ 'activity.comment'|trans }}</dt>
                <dd>
                    {%- if entity.comment.empty -%}
                        <span class="chill-no-data-statement">{{ 'No comment associated'|trans }}</span>
                    {%- else -%}
                        {{ entity.comment|chill_entity_render_box }}
                    {%- endif -%}
                </dd>
            {% endif %}

            {% if t.privateCommentVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) and entity.privateComment.hasCommentForUser(app.user) %}
                {% if t.privateCommentLabel is not empty %}
                    <dt class="inline">{{ t.privateCommentLabel }}</dt>
                {% else %}
                    <dt class="inline">{{ 'Private comment'|trans }}</dt>
                {% endif %}
                <dd>
                    <section class="chill-entity entity-comment-embeddable">
                        <blockquote class="chill-user-quote private-quote">
                            {{ entity.privateComment.comments[userId]|chill_markdown_to_html }}
                        </blockquote>
                    </section>
                </dd>
            {% endif %}

            {% if t.documentsVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
                <dt class="inline">{{ 'Documents'|trans }}</dt>
                <dd>
                    {% if entity.documents|length > 0 %}
                        <ul>
                            {% for d in entity.documents %}
                                <li class="document-list-item">{{ d.title|chill_print_or_message('document.Any title') }} {{ d|chill_document_button_group(d.title, is_granted('CHILL_ACTIVITY_UPDATE', entity), {small: true}) }}</li>
                            {% endfor %}
                        </ul>
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'No document found'|trans }}</span>
                    {% endif %}
                </dd>
            {% endif %}

            {% if t.attendeeVisible and is_granted('CHILL_ACTIVITY_SEE_DETAILS', entity) %}
                <dt class="inline">{{ 'Attendee'|trans }}</dt>
                <dd>
                    {% if entity.attendee is not null %}
                        {{ entity.attendee.name|localize_translatable_string }}
                    {% else %}
                        <span class="chill-no-data-statement">{{ 'None'|trans|capitalize }}</span>
                    {% endif %}
                </dd>
            {% endif %}

        </dl>

    </div>
</div>

<div class="notification notification-list">
    {% set notifications =  chill_list_notifications('Chill\\ActivityBundle\\Entity\\Activity', entity.id) %}
    {% if notifications is not empty %}
        {{ notifications|raw }}
    {% endif %}
</div>

{% set person_id = null %}
{% if person %}
    {% set person_id = person.id %}
{% endif %}

{% set accompanying_course_id = null %}
{% if accompanyingCourse %}
    {% set accompanying_course_id = accompanyingCourse.id %}
{% endif %}

<ul class="record_actions sticky-form-buttons">
    <li class="cancel">
        <a class="btn btn-cancel" href="{{ path('chill_activity_activity_list', { 'person_id': person_id, 'accompanying_period_id': accompanying_course_id } ) }}">
            {{ 'Back to the list'|trans }}
        </a>
    </li>
    <li>
        {% set showGroup = entity.accompanyingPeriod is not null and entity.accompanyingPeriod.hasUser and entity.accompanyingPeriod.user is not same as(app.user)  %}
        <div class="{% if showGroup %}btn-group{% endif %}" {% if showGroup %}role="group"{% endif %}>
            {% if showGroup %}
                <button id="btnGroupNotifyButtons" type="button" class="btn btn-notify dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
                    {{ 'notification.Notify'|trans }}
                </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\\ActivityBundle\\Entity\\Activity', 'entityId': entity.id, 'tos': [entity.accompanyingPeriod.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\\ActivityBundle\\Entity\\Activity', 'entityId': entity.id}) }}">
                            {{ 'notification.Notify any'|trans }}
                        </a>
                    </li>
                </ul>
            {% else %}
                <a class="btn btn-notify" href="{{ chill_path_add_return_path('chill_main_notification_create', {'entityClass': 'Chill\\ActivityBundle\\Entity\\Activity', 'entityId': entity.id}) }}">
                    {{ 'notification.Notify'|trans }}
                </a>
            {% endif %}
        </div>
    </li>
    {% if is_granted('CHILL_ACTIVITY_UPDATE', entity) %}
        <li>
            <a href="{{ path('chill_activity_activity_edit', { 'id': entity.id, 'person_id': person_id, 'accompanying_period_id': accompanying_course_id }) }}"
               class="btn btn-update">{{ 'Edit'|trans }}</a>
        </li>
    {% endif %}
    {% if is_granted('CHILL_ACTIVITY_DELETE', entity) %}
    <li>
        <a href="{{ path('chill_activity_activity_delete', { 'id': entity.id, 'person_id' : person_id, 'accompanying_period_id': accompanying_course_id } ) }}"
           class="btn btn-delete" title="{{ 'Delete'|trans }}"></a>
    </li>
    {% endif %}
</ul>
