{% import 'macro/flask.html' as flask %}

<!doctype html>
<html lang="{{ locale }}">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">

        <title>{% block title %}{% trans %}Authorization interface{% endtrans %}{% endblock %} - {{ website_name|default("Canaille") }}</title>

        <link href="/static/fomanticui/semantic.min.css" rel="stylesheet">
        <link href="/static/fonts/lato.css" rel="stylesheet">
        <link href="/static/css/base.css" rel="stylesheet">
        {% if logo_url %}<link rel="icon" href="{{ favicon_url }}">{% endif %}
        {% block style %}{% endblock %}

        <!--[if lt IE 9]>
        <script>window.html5 || document.write('<script src="/static/html5shiv/html5shiv.min.js"><\/script>')</script>
        <script src="/static/js/respond.min.js"></script>
    <![endif]-->

    </head>

    <body>
        {% block menu %}
            {% if user and menu %}
                <nav class="ui stackable labeled icon menu container">
                    {% if logo_url %}
                        <div class="header item">
                            <a href="/" class="logo">
                                <img class="ui img" src="{{ logo_url }}" alt="{{ website_name }}" />
                            </a>
                        </div>
                    {% endif %}
                    {% if user.can_edit_self %}
                        <a class="item {% if menuitem == "profile" %}active{% endif %}"
                            href="{{ url_for('account.profile_edition', username=user.uid[0]) }}">
                            <i class="id card icon"></i>
                            {% trans %}My profile{% endtrans %}
                        </a>
                    {% endif %}
                    {% if user.can_use_oidc %}
                        <a class="item {% if menuitem == "consents" %}active{% endif %}"
                            href="{{ url_for('oidc.consents.consents') }}">
                            <i class="handshake icon"></i>
                            {% trans %}My consents{% endtrans %}
                        </a>
                    {% endif %}
                    {% if user.can_manage_users %}
                        <a class="item {% if menuitem == "users" %}active{% endif %}"
                            href="{{ url_for('account.users') }}">
                            <i class="address book icon"></i>
                            {% trans %}Users{% endtrans %}
                        </a>
                    {% endif %}
                    {% if user.can_manage_groups %}
                        <a class="item {% if menuitem == "groups" %}active{% endif %}"
                            href="{{ url_for('groups.groups') }}">
                            <i class="users icon"></i>
                            {% trans %}Groups{% endtrans %}
                        </a>
                    {% endif %}
                    {% if user.can_manage_oidc %}
                        <div class="ui dropdown item {% if menuitem == "admin" %}dropdown-active{% endif %}">
                            <i class="settings icon"></i>
                            {% trans %}Admin{% endtrans %}
                            <div class="menu">
                                <a class="item" href="{{ url_for('oidc.clients.index') }}">
                                    <i class="plug icon"></i>
                                    {% trans %}Clients{% endtrans %}
                                </a>
                                <a class="item" href="{{ url_for('oidc.tokens.index') }}">
                                    <i class="key icon"></i>
                                    {% trans %}Tokens{% endtrans %}
                                </a>
                                <a class="item" href="{{ url_for('oidc.authorizations.index') }}">
                                    <i class="user secret icon"></i>
                                    {% trans %}Codes{% endtrans %}
                                </a>
                                <a class="item" href="{{ url_for('admin.mail_index') }}">
                                    <i class="user mail icon"></i>
                                    {% trans %}Emails{% endtrans %}
                                </a>
                            </div>
                        </div>
                    {% endif %}
                    <a class="item" href="{{ url_for('account.logout') }}">
                        <i class="sign out alternate icon"></i>
                        {% trans %}Log out{% endtrans %}
                    </a>
                </nav>
            {% endif %}
        {% endblock %}

        {% block container %}
            <div class="ui container">
                <div class="content">
                    {{ flask.messages() }}
                    {% block content %}{% endblock %}
                </div>
            </div>
        {% endblock %}

        <footer>
            <a href="{{ url_for('account.about') }}">{{ _("About Canaille") }}</a>
        </footer>
        <script src="/static/jquery/jquery.min.js"></script>
        <script src="/static/fomanticui/semantic.min.js"></script>
        <script src="/static/htmx/htmx.min.js"></script>
        <script src="/static/js/base.js"></script>
        <script>
            htmx.config.requestClass = "loading"
        </script>
        {% block script %}{% endblock %}
    </body>
</html>
