{% 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 %}

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

            <div class="denomination h2">
                {{ document.title|chill_print_or_message("No title") }}
            </div>
            {% if document.object.type is not empty %}
                <div>
                    {{ mm.mimeIcon(document.object.type) }}
                </div>
            {% endif %}
            {% if document.category %}
                <div>
                    <p>{{ document.category.name|localize_translatable_string }}</p>
                </div>
            {% endif %}
            {% if document.object.hasTemplate %}
                <div>
                    <p>{{ document.object.template.name|localize_translatable_string }}</p>
                </div>
            {% endif %}
        </div>
        {% if document.date is not null %}
            <div class="aside">
                <div class="dates row text-end">
                    <span>{{ document.date|format_date('short') }}</span>
                </div>
                {% if context == 'person' and accompanyingCourse is defined %}
                    <div class="text-end">
                        <span class="badge bg-primary">
                            <i class="fa fa-random"></i> {{ accompanyingCourse.id }}
                        </span>&nbsp;
                    </div>
                {% elseif context == 'accompanying-period' and person is defined %}
                    <div class="text-end">
                        <span class="badge bg-primary">
                             {{ document.person|chill_entity_render_string }}
                        </span>&nbsp;
                    </div>
                {% endif %}
            </div>
        {% endif %}
    </div>

</div>
{% if document.description is not empty %}
    <div class="item-row">
        <blockquote class="chill-user-quote col">
            {{ document.description|chill_markdown_to_html }}
        </blockquote>
    </div>
{% endif %}
    {% 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 document.course is defined %}
                    <li>
                        {{ chill_entity_workflow_list('Chill\\DocStoreBundle\\Entity\\AccompanyingCourseDocument', document.id) }}
                    </li>
                    {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE_DETAILS', document) %}
                        <li>
                            {{ document.object|chill_document_button_group(document.title) }}
                        </li>
                    {% endif %}
                    {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_DELETE', document) %}
                        <li class="delete">
                            <a href="{{ chill_return_path_or('chill_docstore_accompanying_course_document_delete', {'course': accompanyingCourse.id, 'id': document.id}) }}" class="btn btn-delete"></a>
                        </li>
                    {% endif %}
                    {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_CREATE', document.course) %}
                        <li>
                            <a href="{{ chill_path_add_return_path('chill_doc_store_accompanying_course_document_duplicate', {'id': document.id}) }}" class="btn btn-duplicate" title="{{ 'Duplicate'|trans|e('html_attr') }}"></a>
                        </li>
                    {% endif %}
                    {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_UPDATE', document) %}
                        <li>
                            <a href="{{ path('accompanying_course_document_edit', {'course': accompanyingCourse.id, 'id': document.id }) }}" class="btn btn-update"></a>
                        </li>
                    {% endif %}
                    {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE_DETAILS', document) %}
                        <li>
                            <a href="{{ chill_path_add_return_path('accompanying_course_document_show', {'course': accompanyingCourse.id, 'id': document.id}) }}" class="btn btn-show"></a>
                        </li>
                    {% endif %}
                {% else %}
                    {% if is_granted('CHILL_PERSON_DOCUMENT_SEE_DETAILS', document) %}
                        <li>
                            {{ document.object|chill_document_button_group(document.title) }}
                        </li>
                        <li>
                            <a href="{{ path('person_document_show', {'person': person.id, 'id': document.id}) }}" class="btn btn-show"></a>
                        </li>
                    {% endif %}
                    {% if is_granted('CHILL_PERSON_DOCUMENT_UPDATE', document) %}
                        <li>
                            <a href="{{ path('person_document_edit', {'person': person.id, 'id': document.id}) }}" class="btn btn-update"></a>
                        </li>
                    {% endif %}
                    {% if is_granted('CHILL_PERSON_DOCUMENT_DELETE', document) %}
                        <li class="delete">
                            <a href="{{ chill_return_path_or('chill_docstore_person_document_delete', {'person': person.id, 'id': document.id}) }}" class="btn btn-delete"></a>
                        </li>
                    {% endif %}
                {% endif %}
            </ul>
        </div>
    {% endif %}
