{# list used in context of person, accompanyingPeriod or user #}

<div class="item-bloc">
    <div class="item-row main">
        <div class="item-col">
            <div class="wrap-header">
                <div class="wl-row">
                    {% if calendar.status == 'canceled' %}
                                <div class="badge rounded-pill bg-danger">
                                    <span>{{ 'chill_calendar.canceled'|trans }}: </span>
                                    <span>{{ calendar.cancelReason.name|localize_translatable_string }}</span>
                                </div>
                                    {% endif %}
                            </div>
                            <div class="wl-row">
                                <div class="wl-col title">
                                    <p class="date-label">
                                        {% if calendar.status == 'canceled' %}
                                        <del>
                                            {% endif %}
                                        {% if context == 'person' and calendar.context == 'accompanying_period' %}
                                            <a href="{{ chill_path_add_return_path('chill_person_accompanying_course_index', {'accompanying_period_id': calendar.accompanyingPeriod.id}) }}" style="text-decoration: none;">
                                                <span class="badge bg-primary">
                                                        <i class="fa fa-random"></i> {{ calendar.accompanyingPeriod.id }}
                                                </span>
                                            </a>
                                        {% endif %}
                                        {% if calendar.status == 'canceled' %}
                                            <del>
                                        {% endif %}
                                        {% if calendar.status == 'canceled' %}
                                            <del>
                                        {% endif %}
                                        {% if calendar.endDate.diff(calendar.startDate).days >= 1 %}
                                                {{ calendar.startDate|format_datetime('short', 'short') }}
                                                - {{ calendar.endDate|format_datetime('short', 'short') }}
                                        {% else %}
                                            {{ calendar.startDate|format_datetime('short', 'short') }}
                                                - {{ calendar.endDate|format_datetime('none', 'short') }}
                                        {% endif %}
                                        {% if calendar.status == 'canceled' %}
                                            </del>
                                        {% endif %}

                        <div class="duration short-message">
                            <i class="fa fa-fw fa-hourglass-end"></i>
                            {{ calendar.duration|date('%H:%I') }}
                            {% if false == calendar.sendSMS or null == calendar.sendSMS %}
                                <!-- no sms will be sent -->
                            {% else %}
                                {% if calendar.smsStatus == 'sms_sent' %}
                                    <span title="{{ 'SMS already sent'|trans }}" class="badge bg-info">
                                        <i class="fa fa-check "></i>
                                        <i class="fa fa-envelope "></i>
                                    </span>
                                {% else %}
                                    <span title="{{ 'Will send SMS'|trans }}" class="badge bg-info">
                                        <i class="fa fa-envelope "></i>
                                        <i class="fa fa-hourglass-end "></i>
                                    </span>
                                {% endif %}
                            {% endif %}
                        </div>

                    </div>
                </div>
            </div>

            <div class="item-col">
                <ul class="list-content">
                    {% if calendar.mainUser is not empty %}
                        <span class="badge-user">{{ calendar.mainUser|chill_entity_render_box({'at_date': calendar.startDate}) }}</span>
                    {% endif %}
                </ul>
            </div>

        </div>
    </div>

    {% if calendar.comment.comment is not empty
                    or calendar.users|length > 0
                    or calendar.thirdParties|length > 0
                    or calendar.users|length > 0 %}
                    <div class="item-row details separator">
                        <div class="item-col">
                            {% include '@ChillActivity/Activity/concernedGroups.html.twig' with {
                                'context': calendar.context == 'person' ?  'calendar_person' : 'calendar_accompanyingCourse',
                                'render': 'wrap-list',
                                'entity': calendar
                            } %}
                        </div>

        </div>
    {% endif %}

    {% if calendar.comment.comment is not empty %}
        <div class="item-row details separator">
            <div class="item-col comment">
                {{ calendar.comment|chill_entity_render_box( { 'limit_lines': 3, 'metadata': false } ) }}
            </div>
        </div>
    {% endif %}

    {% if calendar.location is not empty %}
        <div class="item-row separator">
            <div>
                {% if calendar.location.address is not same as(null) and calendar.location.name is not empty %}
                    <i class="fa fa-map-marker"></i>{% endif %}
                {% if calendar.location.name is not empty %}{{ calendar.location.name }}{% endif %}
                {% if calendar.location.address is not same as(null) %}{{ calendar.location.address|chill_entity_render_box({'multiline': false, 'with_picto': (calendar.location.name is empty)}) }}{% else %}
                    <i class="fa fa-map-marker"></i>{% endif %}
                {% if calendar.location.phonenumber1 is not empty %}<i
                    class="fa fa-phone"></i> {{ calendar.location.phonenumber1|chill_format_phonenumber }}{% endif %}
                {% if calendar.location.phonenumber2 is not empty %}<i
                    class="fa fa-phone"></i> {{ calendar.location.phonenumber2|chill_format_phonenumber }}{% endif %}
            </div>
        </div>
    {% endif %}

    {% if calendar.documents is not empty %}
        <div class="item-row separator column">
            <div>
                {{ include('@ChillCalendar/Calendar/_documents.twig.html') }}
            </div>
        </div>
    {% endif %}

    {% if calendar.activity is not null %}
        <div class="item-row separator">
            <div class="item-col">
                <div class="wrap-list">
                    <div class="wl-row">
                        <div class="wl-col title"><h3>{{ 'Activity'|trans }}</h3></div>
                        <div class="wl-col list activity-linked">
                            <h2 class="badge-title">
                                <span class="title_label"></span>
                                <span class="title_action">
                                {{ calendar.activity.type.name | localize_translatable_string }}

                                    {% if calendar.activity.emergency %}
                                        <span class="badge bg-danger rounded-pill fs-6 float-end">{{ 'Emergency'|trans|upper }}</span>
                                    {% endif %}
                            </span>
                            </h2>

                            <ul class="record_actions">
                                <li class="cancel">
                                    <span class="createdBy">
                                         {{ 'Created by'|trans }}
                                        <b>{{ calendar.activity.createdBy|chill_entity_render_string({'at_date': calendar.activity.createdAt}) }}</b>, {{ 'on'|trans }} {{ calendar.activity.createdAt|format_datetime('short', 'short') }}
                                    </span>
                                </li>
                                {% if is_granted('CHILL_ACTIVITY_SEE', calendar.activity) %}
                                    <li>
                                        <a href="{{ chill_path_add_return_path('chill_activity_activity_show', {'id': calendar.activity.id}) }}" class="btn btn-sm btn-show" ></a>
                                    </li>
                                {% endif %}
                            </ul>

                        </div>
                    </div>
                </div>
            </div>
        </div>
    {% endif %}

    <div class="item-row separator">
        {% if show_record_actions is not defined or show_record_actions %}
        <ul class="record_actions">
                {% if is_granted('CHILL_CALENDAR_DOC_EDIT', calendar) and calendar.status is not constant('STATUS_CANCELED', calendar) %}
                    {% if templates|length == 0 %}
                        <li>
                            <a class="btn btn-create"
                               href="{{ chill_path_add_return_path('chill_calendar_calendardoc_new', {'id': calendar.id }) }}">
                                {{ 'chill_calendar.Add a document'|trans }}
                            </a>
                        </li>
                    {% else %}
                        <li>
                            <div class="dropdown">
                                <button class="btn btn-create dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
                                    {{ 'chill_calendar.Add a document'|trans }}
                                </button>
                                <ul class="dropdown-menu">
                                    <li>
                                        <a class="dropdown-item"
                                           href="{{ chill_path_add_return_path('chill_calendar_calendardoc_new', {'id': calendar.id }) }}">
                                            {{ 'chill_calendar.Upload a document'|trans }}
                                        </a>
                                    </li>
                                    {% for template in templates %}
                                    <li>
                                        <a class="dropdown-item"
                                            href="{{ chill_path_add_return_path('chill_docgenerator_generate_from_template', {'template': template.id, 'entityClassName': 'Chill\\CalendarBundle\\Entity\\Calendar', 'entityId': calendar.id}) }}"
                                        >
                                           {{ template.name|localize_translatable_string }}
                                        </a>
                                    </li>
                                    {% endfor %}
                                </ul>
                            </div>
                        </li>
                    {% endif %}
                {% endif %}
            {% if calendar.activity is null and (
                (calendar.context == 'accompanying_period' and is_granted('CHILL_ACTIVITY_CREATE', calendar.accompanyingPeriod))
                or
                (calendar.context == 'person' and is_granted('CHILL_ACTIVITY_CREATE', calendar.person))
                )
                            and calendar.status is not constant('STATUS_CANCELED', calendar)
            %}
                <li>
                    <a class="btn btn-create"
                       href="{{ chill_path_add_return_path('chill_calendar_calendar_to_activity', { 'id': calendar.id }) }}">
                        {{ 'Transform to activity'|trans }}
                    </a>
                </li>
            {% endif %}

            {% if calendar.isInvited(app.user) and not calendar.isCanceled %}
                            {% set invite = calendar.inviteForUser(app.user) %}
                            <li>
                                <div invite-answer data-status="{{ invite.status|e('html_attr') }}"
                                     data-calendar-id="{{ calendar.id|e('html_attr') }}"></div>
                            </li>
                        {% endif %}
                        {% if false %}
                            <li>
                                <a href="{{ chill_path_add_return_path('chill_calendar_calendar_show', { 'id': calendar.id}) }}"
                                   class="btn btn-show "></a>
                            </li>
                        {% endif %}

                        {% if is_granted('CHILL_CALENDAR_CALENDAR_EDIT', calendar) and calendar.status is not constant('STATUS_CANCELED', calendar) %}
                        <li>
                            <a href="{{ chill_path_add_return_path('chill_calendar_calendar_edit', { 'id': calendar.id }) }}"
                               class="btn btn-update "></a>
                        </li>
                        <li>
                            <a href="{{ chill_path_add_return_path('chill_calendar_calendar_cancel', { 'id': calendar.id } ) }}"
                               class="btn btn-action"><i class="bi bi-x-circle"></i> {{ 'Cancel'|trans }}</a>
                        </li>
                        <li>
                            <a href="{{ chill_path_add_return_path('chill_calendar_calendar_cancel', { 'id': calendar.id } ) }}"
                               class="btn btn-action"><i class="bi bi-x-circle"></i> {{ 'Cancel'|trans }}</a>
                        </li>
                        {% endif %}

                        {% if is_granted('CHILL_CALENDAR_CALENDAR_DELETE', calendar) %}
                        <li>
                            <a href="{{ chill_path_add_return_path('chill_calendar_calendar_delete', { 'id': calendar.id } ) }}"
                               class="btn btn-delete "></a>
                        </li>
                        {% endif %}
                    </ul>
        {% endif %}
    </div>

</div>


