{% extends 'site/base.html' %}
{% load i18n %}

{% block content %}
<main class="account">
    <h2>{% trans 'Your Account' %}</h2>

    {% include 'site/fragment_messages.html' %}

    <p>
        {% with username=request.user.username %}
            {% blocktrans %}You are logged in as <strong>{{ username }}</strong>.{% endblocktrans %}
        {% endwith %}
    </p>

    {% if request.user_permissions.control_panel or request.user_permissions.can_review_reports or request.user_permissions.mesh_control %}
        <p>
            {% trans 'You can manage:' %}
        </p>
        <p>
            {% if request.user_permissions.editor_access %}
                <a class="button" href="{% url 'editor.index' %}">{% trans 'Editor' %}</a>
            {% endif %}
            {% if request.user_permissions.control_panel %}
                <a class="button" href="{% url 'control.index' %}">{% trans 'stuff' %}</a>
            {% endif %}
            {% if request.user_permissions.can_review_reports %}
                <a class="button" href="{% url 'site.report_list' %}">{% trans 'reports' %}</a>
            {% endif %}
            {% if request.user_permissions.can_manage_mesh %}
                <a class="button" href="{% url 'mesh.nodes' %}">{% trans 'mesh' %}</a>
            {% endif %}
        </p>
    {% endif %}

    {% if not request.user_permissions.can_review_reports and user_has_reports %}
        <hr>
        <p>
            {% trans 'You have submitted reports.' %}
        </p>
        <p>
            <a class="button" href="{% url 'site.report_list' filter='all' %}">{% trans 'Show your reports' %}</a>
        </p>
    {% endif %}

    <hr>
    <p>
        <a class="button" href="{% url 'site.position_list' %}">{% trans 'Manage custom positions' %}</a>
    </p>
    <p>
        <a class="button" href="{% url 'site.api_secret_list' %}">{% trans 'Manage API secrets' %}</a>
    </p>

    {% if sso_backends %}
    <hr>
        <p>{% trans 'SSO Connections:' %}</p>
        {% for backend, name in sso_backends.not_associated.items %}
        <p><a class="button" href="{% url 'social:begin' backend=backend %}?next={% url 'site.account' %}" target="_self">Link {{ name }}</a></p>
        {% endfor %}
        {% for backend, name in sso_backends.associated.items %}
        <p><a class="button delete" href="{% url 'social:disconnect' backend=backend %}?next={% url 'site.account' %}" target="_self">Unlink {{ name }}</a></p>
        {% endfor %}
    {% endif %}

    <hr>
    <p>
        <a class="button" href="{% url 'site.logout' %}">{% trans 'Log out' %}</a>
        <a class="button" href="{% url 'site.account.manage' %}">{% trans 'Manage account' %}</a>
    </p>
</main>
{% endblock %}
