{% set_global can_view = false %}
{% set_global can_edit = false %}
{% set_global can_delete = false %}

{% if current_user %}
    {% if current_user.is_superuser %}
        {% set_global can_view = true %}
        {% set_global can_edit = true %}
        {% set_global can_delete = true %}
    {% else %}
        {% for groupe in current_user.groupes %}
            {% for perm in groupe.permissions %}
                {% if perm.resource_key == resource_key %}
                    {% if perm.can_read %}{% set_global can_view = true %}{% endif %}
                    {% if perm.can_update %}{% set_global can_edit = true %}{% endif %}
                    {% if perm.can_delete %}{% set_global can_delete = true %}{% endif %}
                {% endif %}
            {% endfor %}
        {% endfor %}
    {% endif %}
{% endif %}

{% if can_view or can_edit or can_delete %}
    <div class="admin-menu">
        <button class="admin-menu__trigger" type="button" aria-haspopup="true" aria-expanded="false">
            <svg viewBox="0 0 24 24" fill="currentColor" width="16" height="16">
                <circle cx="12" cy="5" r="1.5"/><circle cx="12" cy="12" r="1.5"/><circle cx="12" cy="19" r="1.5"/>
            </svg>
        </button>
        <div class="admin-menu__dropdown">

            {% if can_view %}
            <a href="{{ admin_prefix }}/{{ resource_key }}/{{ entry_id }}/detail{% if return_qs %}?return_qs={{ return_qs | urlencode }}{% endif %}" class="admin-menu__item">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>
                {% if admin_list_btn_detail %}{{ admin_list_btn_detail }}{% else %}Voir{% endif %}
            </a>
            {% endif %}

            {% if can_edit %}
            <a href="{{ admin_prefix }}/{{ resource_key }}/{{ entry_id }}/edit{% if return_qs %}?return_qs={{ return_qs | urlencode }}{% endif %}" class="admin-menu__item">
                <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/></svg>
                {% if admin_list_btn_edit %}{{ admin_list_btn_edit }}{% else %}Modifier{% endif %}
            </a>
            {% endif %}

            {% if can_delete %}
            <div class="admin-menu__separator"></div>
            <form method="POST" action="{{ admin_prefix }}/{{ resource_key }}/{{ entry_id }}/delete">
                {% csrf %}
                {% if return_qs %}<input type="hidden" name="return_qs" value="{{ return_qs }}">{% endif %}
                <button type="submit" class="admin-menu__item admin-menu__item--danger" data-confirm-delete="{% if admin_list_confirm_delete %}{{ admin_list_confirm_delete }}{% else %}Vraiment supprimer ?{% endif %}">
                    <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" width="14" height="14"><polyline points="3 6 5 6 21 6"/><path d="M19 6l-1 14H6L5 6"/><path d="M10 11v6"/><path d="M14 11v6"/><path d="M9 6V4h6v2"/></svg>
                    {% if admin_list_btn_delete %}{{ admin_list_btn_delete }}{% else %}Supprimer{% endif %}
                </button>
            </form>
            {% endif %}

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