{% load i18n cosinnus_tags %}

{% group_url 'cosinnus:group-detail' group=group as group_detail_page %}
{% group_url 'cosinnus:group-edit' group=group as group_edit_page %}
{% group_url 'cosinnus:group-dashboard' group=group as group_dashboard_page %}
{% group_url 'cosinnus:group-microsite' group=group as group_microsite_page %}


<div class="btn-group w100 large-space">
    <button type="button" class="btn btn-appnavi w100{% if user|has_read_access:group %} dropdown-toggle{% endif %}" {% if user|has_read_access:group %}data-toggle="dropdown"{% endif %}>
        <ul class="media-list">
            <li class="media">
                <a class="pull-left" href="#">
                </a>
                <a class="pull-left" href="#">
                    <i class="fa fa-book"></i>
                </a>
                {% if user|has_read_access:group %}
                <a class="pull-right" href="#">
                    <i class="fa fa-caret-down"></i>
                </a>
                {% endif %}
                <div class="media-body">
                    {% if active_app %}
                      {% for app in apps %}
                        {% if app.active %}
                          {{ app.label }}
                        {% endif %}
                      {% endfor %}
                    {% elif request.path == group_edit_page %}  
                        {% trans "Settings" %}
                    {% elif request.path == group_detail_page or request.path == group_members_map_page %}
                        {% trans "Members" %}
                    {% elif request.path == group_microsite_page %}  
                        {% trans "Microsite" %}
                    {% elif request.path == group_dashboard_page %}
                        {% trans "Dashboard" %}
                    {% else %}
                      {% trans "Choose App" %}
                    {% endif %}
                </div>
            </li>
        </ul>
    </button>
    
    {% if user|has_read_access:group %}
    <ul class="dropdown-menu appnavi-dropdown-menu w100" role="menu">
        <li class="app-main appnavi-listelement fine-space">
            <a href="{% group_url 'cosinnus:group-dashboard' group=group %}{% if SETTINGS.COSINNUS_MICROSITES_ENABLED %}{% if group.public or user.is_superuser %}?browse=true{% endif %}{% endif %}">
                <i class="fa fa-th-large"></i>
                {% trans "Dashboard" %}
            </a>
        </li>
        {% if SETTINGS.COSINNUS_MICROSITES_ENABLED %}
        <li class="app-main appnavi-listelement fine-space">
            <a href="{{ group_microsite_page }}">
                <i class="fa fa-lightbulb-o"></i>
                {% trans "Microsite" %}
            </a>
        </li>
        {% endif %}
        {% for app in apps %}
            {% captureas app_css_class %}{% if app.app == 'cosinnus_todo' %}app-todos{% elif app.app == 'cosinnus_note' %}app-main{% elif app.app == 'cosinnus_poll' %}app-poll{% elif app.app == 'cosinnus_marketplace' %}app-marketplace{% elif app.app == 'cosinnus_file' %}app-files{% elif app.app == 'cosinnus_etherpad' %}app-etherpad{% elif app.app == 'cosinnus_event' %}app-calendar{% elif app.app %}app-{{ COSINNUS_CURRENT_APP }}{% endif %}{% endcaptureas %}
            {% captureas app_icon %}{% if app.app == 'cosinnus_todo' %}fa-tasks{% elif app.app == 'cosinnus_note' %}fa-book{% elif app.app == 'cosinnus_poll' %}fa-bar-chart{% elif app.app == 'cosinnus_marketplace' %}fa-exchange{% elif app.app == 'cosinnus_file' %}fa-file{% elif app.app == 'cosinnus_etherpad' %}fa-file-text{% elif app.app == 'cosinnus_event' %}fa-calendar{% elif app.app %}app-{{ COSINNUS_CURRENT_APP }}{% endif %}{% endcaptureas %}
        
	        <li class="{{app_css_class}} appnavi-listelement {% if app.active %}active{% endif %}">
	            <a href="{{ app.url }}">
	                <i class="fa {{ app_icon }}"></i>
	                {{ app.label }}
	            </a>
	        </li>
        {% endfor %}
        <li class="app-main appnavi-listelement {% if user|has_write_access:group %}fine-space{% endif %}">
            <a href="{{ group_detail_page }}">
                <i class="fa fa-group"></i>
                {% trans "Members" %}
            </a>
        </li>
        {% if user|has_write_access:group %}
        <li class="app-main appnavi-listelement">
            <a href="{{ group_edit_page }}">
                <i class="fa fa-cogs"></i>
                {% trans "Settings" %}
            </a>
        </li>
        {% endif %}
    </ul>
    {% endif %} 
</div><!-- btn-group -->