{% load i18n %}
{% load evelinks %}

<li class="top-user-menu dropdown{% if request.user.profile.main_character %} with-main-character{% endif %}">
    <a href="#" class="dropdown-toggle" type="button" id="top-user-menu" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
        {% if request.user.profile.main_character %}
            {% with request.user.profile.main_character as main %}
                <img class="img-rounded ra-avatar" src="{{ main.character_id|character_portrait_url:32 }}" alt="{{ main.character_name }}">
            {% endwith %}
        {% else %}
            {% translate "Menu" %}
        {% endif %}
        <span class="caret"></span>
    </a>
    <ul class="dropdown-menu" aria-labelledby="top-user-menu">
        <!-- user avatar -->
        {% if request.user.profile.main_character %}
            <li>
                {% with request.user.profile.main_character as main %}
                    <p class="text-center">
                        <img class="img-default ra-avatar" src="{{ main.character_id|character_portrait_url:256 }}" alt="{{ main.character_name }}">
                    </p>

                    <p class="text-center">
                        <span class="text-white text-primary" style="display: block; font-size: 1rem;">{{ main.character_name }}</span>
                        <span class="text-white text-primary" style="display: block; font-size: 1rem;">{{ main.corporation_name }}</span>

                        {% if main.alliance_name %}
                            <span class="text-white text-primary" style="display: block; font-size: 1rem;">{{ main.alliance_name }}</span>
                        {% endif %}
                    </p>
                {% endwith %}
            </li>
            <li role="separator" class="divider"></li>
        {% endif %}

        <li>
            <form id="f-lang-select" class="navbar-form" action="{% url 'set_language' %}" method="post">
                {% csrf_token %}

                <div class="form-group">
                    <select onchange="this.form.submit()" class="form-control" id="lang-select" name="language">
                        {% get_language_info_list for LANGUAGES as languages %}

                        {% for language in languages %}
                            <option value="{{ language.code }}"{% if language.code == LANGUAGE_CODE %} selected="selected"{% endif %}>
                                {{ language.name_local }} ({{ language.code }})
                            </option>
                        {% endfor %}
                    </select>
                </div>
            </form>
        </li>
        <li role="separator" class="divider"></li>

        <!-- night mode toggle -->
        {% include 'allianceauth/night-toggle.html' %}

        <!-- tnnt related menu items -->
        {% include 'allianceauth/tnnt-menu-top.html' %}

        <!-- admin related menu items -->
        {% include 'allianceauth/admin-menu-top.html' %}

        <!-- logout / login -->
        <li role="separator" class="divider"></li>
        {% if user.is_authenticated %}
            <li><a href="{% url 'logout' %}">{% translate "Logout" %}</a></li>
        {% else %}
            <li><a href="{% url 'authentication:login' %}">{% translate "Login" %}</a></li>
        {% endif %}
    </ul>
</li>
