{% import "@ChillDocStore/Macro/macro.html.twig" as m %}
{% import "@ChillDocStore/Macro/macro_mimeicon.html.twig" as mm %}
{% import '@ChillPerson/Macro/updatedBy.html.twig' as mmm %}

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

{% set accompanying_course_id = null %}
{% if activity.accompanyingPeriod %}
    {% set accompanying_course_id = activity.accompanyingPeriod.id %}
{% endif %}

<div class="item-row">
    <div class="item-two-col-grid">
        <div class="title">
            {% if document.isPending %}
                <div class="badge text-bg-info" data-docgen-is-pending="{{ document.id }}">{{ 'docgen.Doc generation is pending'|trans }}</div>
            {% elseif document.isFailure %}
                <div class="badge text-bg-warning">{{ 'docgen.Doc generation failed'|trans }}</div>
            {% endif %}

            <div>
                <div>
                    <div class="badge-activity-type-simple">
                        {{ activity.type.name | localize_translatable_string }}
                    </div>
                    {% if activity.emergency %}
                        <span class="badge bg-danger rounded-pill fs-6 float-end">{{ 'Emergency'|trans|upper }}</span>
                    {% endif %}
                </div>
            </div>
            <div class="denomination h2">
                {{ document.title|chill_print_or_message("No title") }}
            </div>
            {% if document.hasTemplate %}
                <div>
                    <p>{{ document.template.name|localize_translatable_string }}</p>
                </div>
            {% endif %}
        </div>
        <div class="aside">
            <div class="dates row text-end">
                <span>{{ document.createdAt|format_date('short') }}</span>
            </div>
            {% if activity.accompanyingPeriod is not null and context == 'person' %}
                <div class="text-end">
                    <span class="badge bg-primary">
                        <i class="fa fa-random"></i> {{ activity.accompanyingPeriod.id }}
                    </span>&nbsp;
                </div>
            {% endif %}
        </div>
    </div>
</div>

{% if show_actions %}
    <div class="item-row separator">
        <div class="item-col item-meta">
            {{ mmm.createdBy(document) }}
        </div>
        <ul class="item-col record_actions flex-shrink-1">
            {% if is_granted('CHILL_ACTIVITY_SEE_DETAILS', activity) %}
                <li>
                    {{ document|chill_document_button_group(document.title, is_granted('CHILL_ACTIVITY_UPDATE', activity), {small: false})  }}
                </li>
            {% endif %}
            {% if is_granted('CHILL_ACTIVITY_SEE', activity)%}
                <li>
                    <a href="{{ chill_path_add_return_path('chill_activity_activity_show', {'id': activity.id, 'person_id': person_id, 'accompanying_period_id': accompanying_course_id}) }}" class="btn btn-show"></a>
                </li>
            {% endif %}
            {% if is_granted('CHILL_ACTIVITY_UPDATE', activity) %}
                <li>
                    <a href="{{ chill_path_add_return_path('chill_activity_activity_edit', {'id': activity.id, 'person_id': person_id, 'accompanying_period_id': accompanying_course_id }) }}" class="btn btn-edit"></a>
                </li>
            {% endif %}
        </ul>
    </div>
{% endif %}
