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

{% if document is null %}
    <div class="alert alert-warning">
        {{ 'workflow.Document deleted'|trans }}
    </div>
{% else %}
    <div class="flex-table accompanying-course-work">
        <div class="item-bloc document-item bg-chill-llight-gray">
            <div class="row justify-content-center my-4">
                <div class="col-2">
                    <i class="fa fa-4x fa-file-text-o text-success"></i>
                </div>
                <div class="col-8">
                    <h3>{{ document.title }}</h3>

                    {{ mm.mimeIcon(document.object.type) }}

                    {% if document.description is not empty %}
                        <blockquote class="chill-user-quote mt-4">
                            {{ document.description }}
                        </blockquote>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>

    {% set freezed = false %}
    {% for step in entity_workflow.stepsChained %}
        {% if loop.last %}
            {% if step.previous is not null and step.previous.freezeAfter == true %}
                {% set freezed = true %}
            {% endif %}
        {% endif %}
    {% endfor %}

    {% if display_action is defined and display_action == true %}
        <ul class="record_actions">
            {% for dam in display_action_more|default([]) %}
                <li>
                    {{ dam|raw }}
                </li>
            {% endfor %}
            {% if document.course != null and is_granted('CHILL_PERSON_ACCOMPANYING_PERIOD_SEE', document.course) %}
                <li>
                    <a href="{{ path('chill_person_accompanying_course_index', {'accompanying_period_id': document.course.id}) }}" class="btn btn-show change-icon">
                        <i class="fa fa-random"></i> {{ 'Course number'|trans }} {{ document.course.id }}
                    </a>
                </li>
            {% endif %}
            <li>
                {{ document.object|chill_document_button_group(document.title, not freezed) }}
            </li>
            {% if is_granted('CHILL_ACCOMPANYING_COURSE_DOCUMENT_SEE', document) and document.course != null %}
                <li>
                    <a href="{{ chill_path_add_return_path('accompanying_course_document_show', {'course': document.course.id, 'id': document.id}) }}" class="btn btn-show"></a>
                </li>
            {% endif %}
        </ul>
    {% endif %}
{% endif %}
