{% extends 'base.html.twig' %}
{% set menu = 'resources' %}

{% block body %}

<a href="{{ path('users') }}" class="btn btn-link">« {{ "users.back"|trans }}</a>

<h1 class="display-4 font-weight-lighter d-flex justify-content-between">{{ "calendars.for"|trans({'who': principal.displayName}) }} <a href="{{ path('calendar_create', {username: username}) }}" class="btn btn-sm btn-success mb-auto mt-auto">+ {{ "calendars.new"|trans }}</a></h1>

<div class="list-group mt-5">
{% for calendar in calendars %}
    <div class="list-group-item list-group-item-action p-3">
        <div class="d-flex w-100 justify-content-between">
            <h5 class="mb-1 mr-auto">{{ calendar.displayName }} <span class="badge badge-pill" style="background-color: {{ calendar.calendarColor }}">&nbsp;</span></h5>
            <div class="mr-0 text-right d-md-block d-none">
                <a href="#" data-sharees-href="{{ path('calendar_shares',{username: username, calendarid: calendar.calendar.id})}}" data-href="{{ path('calendar_share_add', {username: principal.username, instanceid: calendar.id}) }}" class="btn btn-sm btn-outline-info ml-1 share-modal">🔗 {{ "sharing"|trans }}</a>
                <a href="{{ path('calendar_edit',{username: username, id: calendar.id})}}" class="btn btn-sm btn-outline-primary ml-1">✎ {{ "edit"|trans }}</a>
                <a href="#" data-href="{{ path('calendar_delete',{username: username, id: calendar.id})}}" data-flavour="calendars" class="btn btn-sm btn-outline-danger ml-1 delete-modal">⚠ {{ "delete"|trans }}</a>
            </div>
        </div>
        <p class="mb-1">{{ calendar.description }}</p>
        <small>{{ "calendars.uri"|trans }} : <code>{{ calendar.uri }}</code>
        {% if calendar.calendar.components|split(',')|length > 0 %}
            {% if constant('\\App\\Entity\\Calendar::COMPONENT_EVENTS') in calendar.calendar.components %}<span class="badge badge-success">{{ "calendars.component.events"|trans }}</span>{% endif %}
            {% if constant('\\App\\Entity\\Calendar::COMPONENT_NOTES') in calendar.calendar.components %}<span class="badge badge-info">{{ "calendars.component.notes"|trans }}</span>{% endif %}
            {% if constant('\\App\\Entity\\Calendar::COMPONENT_TODOS') in calendar.calendar.components %}<span class="badge badge-primary">{{ "calendars.component.todos"|trans }}</span>{% endif %}
        {% endif %}
         — {{ "calendars.entries"|trans({'%count%': calendar.calendar.objects|length}) }}
        </small>
        <div class="btn-group btn-group-sm mt-3 d-flex d-md-none" role="group">
            <a href="#" data-sharees-href="{{ path('calendar_shares',{username: username, calendarid: calendar.calendar.id})}}" data-href="{{ path('calendar_share_add', {username: principal.username, instanceid: calendar.id}) }}" class="btn btn-outline-info share-modal">🔗 {{ "sharing"|trans }}</a>
            <a href="{{ path('calendar_edit',{username: username, id: calendar.id})}}" class="btn btn-outline-primary">✎ {{ "edit"|trans }}</a>
            <a href="#" data-href="{{ path('calendar_delete',{username: username, id: calendar.id})}}" data-flavour="calendars" class="btn btn-outline-danger delete-modal">⚠ {{ "delete"|trans }}</a>
        </div>
    </div>
{% endfor %}
</div>

{% if shared|length > 0 %}
    <h2 class="display-5 mt-4 font-weight-lighter">{{ "calendars.shared.with"|trans({'who': principal.displayName}) }}</h2>

    <div class="list-group mt-3">
    {% for calendar in shared %}
        <div class="list-group-item list-group-item-action p-3">
            <div class="d-flex w-100 justify-content-between">
                <h5 class="mb-1 mr-auto">
                    {{ calendar.displayName }}
                    {% if calendar.access == constant('\\App\\Entity\\CalendarInstance::ACCESS_READWRITE') %}
                        <span class="badge badge-success ml-1">{{ ('calendar.share_access.' ~ calendar.access)|trans }}</span>
                    {% else %}
                        <span class="badge badge-info ml-1">{{ ('calendar.share_access.' ~ calendar.access)|trans }}</span>
                    {% endif %}
                    <span class="badge badge-pill" style="background-color: {{ calendar.calendarColor }}">&nbsp;</span>
                </h5>
                <div class="mr-0 text-right d-md-block d-none">
                    <a href="{{ path('calendar_edit',{username: username, id: calendar.id})}}" class="btn btn-sm btn-outline-primary ml-1">✎ {{ "edit"|trans }}</a>
                    <a href="#" data-href="{{ path('calendar_revoke',{username: username, id: calendar.id})}}" data-flavour="revoke" class="btn btn-sm btn-outline-danger ml-1 delete-modal">🚫 {{ "revoke"|trans }}</a>
                </div>
            </div>
            <p class="mb-1">{{ calendar.description }}</p>
            <small>{{ "calendars.uri"|trans }} : <code>{{ calendar.uri }}</code>
            {% if calendar.calendar.components|split(',')|length > 0 %}
                {% if constant('\\App\\Entity\\Calendar::COMPONENT_EVENTS') in calendar.calendar.components %}<span class="badge badge-success">{{ "calendars.component.events"|trans }}</span>{% endif %}
                {% if constant('\\App\\Entity\\Calendar::COMPONENT_NOTES') in calendar.calendar.components %}<span class="badge badge-info">{{ "calendars.component.notes"|trans }}</span>{% endif %}
                {% if constant('\\App\\Entity\\Calendar::COMPONENT_TODOS') in calendar.calendar.components %}<span class="badge badge-primary">{{ "calendars.component.todos"|trans }}</span>{% endif %}
            {% endif %}
            — {{ "calendars.entries"|trans({'%count%': calendar.calendar.objects|length}) }}
            </small>
            <div class="btn-group btn-group-sm mt-3 d-flex d-md-none" role="group">
                <a href="{{ path('calendar_edit',{username: username, id: calendar.id})}}" class="btn btn-outline-primary">✎ {{ "edit"|trans }}</a>
                <a href="#" data-href="{{ path('calendar_revoke',{username: username, id: calendar.id})}}" data-flavour="revoke" class="btn btn-outline-danger delete-modal">🚫 {{ "revoke"|trans }}</a>
            </div>
        </div>
    {% endfor %}
    </div>

    {% include '_partials/delete_modal.html.twig' with {flavour: 'revoke'} %}
{% endif %}

{% include '_partials/share_modal.html.twig' with {principals: allPrincipals} %}
{% include '_partials/delete_modal.html.twig' with {flavour: 'calendars'} %}

{% endblock %}