{% load base_tags %}
{% load perm_tags %}
{% load i18n %}


{% has_perm user site_settings.change_setting as can_edit_setting %}
{% has_perm user user_groups.add_group as can_add_group %}

{% if nav_object %}
    {% has_perm user user_groups.view_group nav_object as can_view_group %}
    {% has_perm user user_groups.change_group nav_object as can_edit_group %}
    {% has_perm user user_groups.delete_group nav_object as can_delete_group %}
    {% has_perm user user_groups.add_groupmembership nav_object as can_add_member %}
{% else %}
    {% has_perm user user_groups.add_groupmembership as can_add_member %}
    {% has_perm user user_groups.view_group as can_view_group %}
    {% has_perm user user_groups.change_group as can_edit_group %}
{% endif %}

<ul id="module-tabs" class="tabs">
    {% if user.is_authenticated %}
    <li class="dropdown" data-dropdown="dropdown">
        <a href="#" class="dropdown-toggle">{% trans "Tendenci" %}</a>
        <ul class="dropdown-menu">
            <a href="{% url dashboard %}" title="Tendenci Home Page">{% trans "Dashboard" %}</a>
            <li><a href="{% url profile.index %}">{% trans "My Profile" %}</a></li>
            <li><a href="{% url auth_logout %}">{% trans "Log Off" %}</a></li>
        </ul>
    </li>
    {% endif %}
    <li class="dropdown active" data-dropdown="dropdown">
        <a href="#" class="dropdown-toggle">{% firstof MODULE_GROUPS_LABEL trans 'Groups' %}</a>
        {% if nav_object %}
        <div class="dropdown-menu">
        <ul class="first">
            <li class="heading">{% trans "All Groups" %}</li>
            <li class="divider"></li>
        {% else %}
            <div>
            <ul class="dropdown-menu">
        {% endif %}
            {% if can_edit_setting %}
                <li><a href="{% url settings.index "module" "groups" %}">{% trans "Settings" %}</a></li>
            {% endif %}
            <li><a href="{% url groups %}">{% trans "Group List" %}</a></li>
            {% if can_add_group %}
                <li><a href="{% url group.add %}">{% trans "Add Group" %}</a></li>
            {% endif %}
            {% if request.user.is_superuser %}
                <li><a href="{% url group.import_add %}">{% trans "Import" %}</a></li>
            {% endif %}
        </ul>
        {% if nav_object %}
            {% if can_view_group or can_edit_group %}
            <ul>
                <li class="heading">{% trans "This Group" %}</li>
                <li class="divider"></li>
                {% if group.type != "membership" %}
                {% if can_view_group %}
                    <li><a href="{{ nav_object.get_absolute_url }}">{% trans "View Group" %}</a></li>
                {% endif %}
                {% endif %}
                {% if can_edit_group %}
                    <li><a href="{% url group.edit nav_object.slug %}">{% trans "Edit Group" %}</a></li>
                    <a href="{% url group.edit_perms nav_object.id %}">{% trans "Edit Permissions" %}</a></li>
                {% endif %}
                {% if group.type != "membership" %}
                <li class="divider"></li>
                {% if can_add_member %} 
                <li><a href="{% url group.adduser nav_object.slug %}">{% trans "Add Users" %}</a></li>
                {% endif %}
                {% if nav_object.allow_self_add and user.is_authenticated or can_add_member %}
                <li><a href="{% url group.selfadd nav_object.slug user.id %}">{% trans "Add Myself to Group" %}</a></li>
                {% endif %}
                {% if can_delete_group %}
                    <li class="divider"></li>
                    <li><a class="delete" href="{% url group.delete nav_object.pk %}">{% trans "Delete Group" %}</a></li>
                {% endif %}
                {% endif %}
            </ul>
            {% endif %}
        {% endif %}
        </div>
    </li>
</ul>
