{% extends '@ChillMain/layout.html.twig' %}

{% block css %}
    {{ parent() }}
    {{ encore_entry_link_tags('mod_pickentity_type') }}

    <style type="text/css">
        form.remove {
            display: inline-block;
            padding: 1px;
            border: 1px solid transparent;
            border-radius: 4px;
        }
        form:hover {
            animation-duration: 0.5s;
            animation-name: onHover;
            animation-iteration-count: 1;
            border: 1px solid #dee2e6;
            border-radius: 4px;
        }
        form.remove button.remove {
            display: inline;
            background-color: unset;
            border: none;
            color: var(--bs-chill-red);
        }

        @keyframes onHover {
           from {
               border: 1px solid transparent;
           }
           to {
               border: 1px solid #dee2e6;
           }
        }
    </style>
{% endblock %}

{% block js %}
    {{ parent() }}
    {{ encore_entry_script_tags('mod_pickentity_type') }}
{% endblock %}

{% block title 'user_group.my_groups'|trans %}

{% block content %}
    <h1>{{ block('title') }}</h1>

    {% if paginator.totalItems == 0 %}
        <p>{{ 'user_group.no_user_groups'|trans }}</p>
    {% else %}
        <div class="flex-table">
            {% for entity in groups %}
                <div class="item-bloc">
                    <div class="item-row">
                        <div class="wrap-header">
                            <div class="wh-row">
                                <div class="wh-col">
                                    {{ entity|chill_entity_render_box }}
                                </div>
                                <div class="wh-col">
                                    {%- if not entity.active -%}
                                        <div>
                                            <span class="badge bg-danger">{{ 'user_group.inactive'|trans }}</span>
                                        </div>&nbsp;
                                    {%- endif -%}
                                    <div>{{ 'user_group.with_count_users'|trans({'count': entity.users|length}) }}</div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="item-row separator">
                        <div class="wrap-list">
                            <div class="wl-row">
                                <div class="wl-col title">
                                    <strong>{{ 'user_group.with_users'|trans }}</strong>
                                </div>
                                <div class="wl-col list">
                                    {% if entity.users.contains(app.user) %}
                                        {% if is_granted('CHILL_MAIN_USER_GROUP_APPEND_TO_GROUP', entity) %}
                                            <form class="remove" method="POST" action="{{ chill_path_add_return_path('chill_main_user_groups_remove_user', {'id': entity.id, 'userId': app.user.id}) }}">
                                                <p class="wl-item">
                                                    {{ 'user_group.me'|trans }}
                                                    <button class="remove" type="submit"><i class="fa fa-times"></i></button>
                                                </p>
                                            </form>
                                        {% else %}
                                            <p class="wl-item">
                                                {% if entity.users|length > 1 %}{{ 'user_group.me_and'|trans }}{% else %}{{ 'user_group.me_only'|trans }}{% endif %}
                                            </p>
                                        {% endif %}
                                    {% endif %}
                                    {% for user in entity.userListByLabelAscending %}
                                        {% if user is not same as app.user %}
                                            {% if is_granted('CHILL_MAIN_USER_GROUP_APPEND_TO_GROUP', entity) %}
                                                <form class="remove" method="POST" action="{{ chill_path_add_return_path('chill_main_user_groups_remove_user', {'id': entity.id, 'userId': user.id}) }}">
                                                    <p class="wl-item">
                                                        <span class="badge-user">
                                                            {{ user|chill_entity_render_box }}
                                                        </span>
                                                        <button class="remove" type="submit"><i class="fa fa-times"></i></button>
                                                    </p>
                                                </form>
                                            {% else %}
                                                <p class="wl-item">
                                                    <span class="badge-user">
                                                        {{ user|chill_entity_render_box }}
                                                    </span>
                                                </p>
                                            {% endif %}
                                        {% endif %}
                                    {% endfor %}
                                </div>
                            </div>
                        </div>
                    </div>
                    {% if entity.adminUsers|length > 0 %}
                        <div class="item-row separator">
                            <div class="wrap-list">
                                <div class="wl-row">
                                    <div class="wl-col title">
                                        <strong>{{ 'user_group.adminUsers'|trans }}</strong>
                                    </div>
                                    <div class="wl-col list">
                                        {% if entity.adminUsers.contains(app.user) %}
                                            <p class="wl-item">{% if entity.adminUsers|length > 1 %}{{ 'user_group.me_and'|trans }}{% else %}{{ 'user_group.me_only'|trans }}{% endif %}</p>
                                        {% endif %}
                                        {% for user in entity.adminUserListByLabelAscending %}
                                            {% if user is not same as app.user %}
                                                <p class="wl-item">
                                                    <span class="badge-user">
                                                        {{ user|chill_entity_render_box }}
                                                    </span>
                                                </p>
                                            {% endif %}
                                        {% endfor %}
                                    </div>
                                </div>
                            </div>
                        </div>
                    {% endif -%}
                    {%- set form = forms.offsetGet(entity) %}
                    {%- if form is not null -%}
                        <div class="item-row separator">
                            <ul class="record_actions slim">
                                <li>
                                    {{- form_start(form) -}}
                                    {{- form_widget(form.users) -}}
                                    {{- form_end(form) -}}
                                </li>
                            </ul>
                        </div>
                    {%- endif %}
                </div>
            {% endfor %}
        </div>

        {{ chill_pagination(paginator) }}
    {% endif %}
{% endblock %}
