{% 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 c = document.calendar %}


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

            <div>

                <span class="badge-calendar-simple">
                    {{ 'Calendar'|trans }}
                    {% if c.endDate.diff(c.startDate).days >= 1 %}
                        {{ c.startDate|format_datetime('short', 'short') }}
                        - {{ c.endDate|format_datetime('short', 'short') }}
                    {% else %}
                        {{ c.startDate|format_datetime('short', 'short') }}
                        - {{ c.endDate|format_datetime('none', 'short') }}
                    {% endif %}
                </span>
            </div>

            <div class="denomination h2">
                {{ document.storedObject.title|chill_print_or_message("No title") }}
            </div>
            {% if document.storedObject.hasTemplate %}
                <div>
                    <p>{{ document.storedObject.template.name|localize_translatable_string }}</p>
                </div>
            {% endif %}
        </div>
        <div class="aside">
            <div class="dates row text-end">
                <span>{{ document.storedObject.createdAt|format_date('short') }}</span>
            </div>
            {% if c.accompanyingPeriod is not null and context == 'person' %}
                <div class="text-end">
                    <span class="badge bg-primary">
                        <i class="fa fa-random"></i> {{ c.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_CALENDAR_DOC_SEE', document) %}
                <li>
                    {{ document.storedObject|chill_document_button_group(document.storedObject.title, is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c)) }}
                </li>
            {% endif %}
            {% if is_granted('CHILL_CALENDAR_CALENDAR_EDIT', c) %}
                <li>
                    <a href="{{ chill_path_add_return_path('chill_calendar_calendar_edit', {'id': c.id, 'docId': document.id}) }}" class="btn btn-edit"></a>
                </li>
            {% endif %}
        </ul>
    </div>
{% endif %}
