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

<!doctype html>
<html lang="{{ locale }}">
    <head>
        <title>{% block title -%}{% trans %}Authorization interface{% endtrans %}{%- endblock %} - {{ website_name|default("Canaille") }}</title>

        {% if not is_boosted %}
            <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">

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

    <body{% if config["CANAILLE"]["JAVASCRIPT"] and config["CANAILLE"]["HTMX"] %} hx-boost="true"{% endif %}>
        {% block menu %}
            {% if menu %}
                <div class="ui container menu-container">
                    <nav class="ui stackable labeled icon seven item {% if self.submenu() | trim %}top attached{% endif %} menu">
                        {% if logo_url %}
                            <a href="/" class="item logo">
                                <img class="ui img" src="{{ logo_url }}" alt="{{ website_name }}" />
                            </a>
                        {% endif %}

                        {% if user %}
                            {% if user.can_edit_self %}
                                <a class="item {% if menuitem is defined and menuitem == "profile" %}active{% endif %}"
                                   href="{{ url_for('core.account.profile_edition', edited_user=user) }}">
                                    <i class="id card icon"></i>
                                    {% trans %}Profile{% endtrans %}
                                </a>
                            {% endif %}
                            {% if features.has_oidc and user.can_use_oidc %}
                                <a class="item {% if menuitem is defined and menuitem == "consents" %}active{% endif %}"
                                   href="{{ url_for('oidc.consents.consents') }}">
                                    <i class="handshake icon"></i>
                                    {% trans %}Consents{% endtrans %}
                                </a>
                            {% endif %}
                            {% if user.can_manage_users %}
                                <a class="item {% if menuitem is defined and menuitem == "users" %}active{% endif %}"
                                   href="{{ url_for('core.account.users') }}">
                                    <i class="address book icon"></i>
                                    {% trans %}Users{% endtrans %}
                                </a>
                            {% endif %}
                            {% if user.can_manage_groups %}
                                <a class="item {% if menuitem is defined and menuitem == "groups" %}active{% endif %}"
                                   href="{{ url_for('core.groups.groups') }}">
                                    <i class="users icon"></i>
                                    {% trans %}Groups{% endtrans %}
                                </a>
                            {% endif %}
                            {% if user.can_manage_oidc %}
                                <a class="item {% if menuitem is defined and menuitem == "admin" %}active{% endif %}" href="{{ url_for('core.admin.mail_index') }}">
                                    <i class="settings icon"></i>
                                    {% trans %}Admin{% endtrans %}
                                </a>
                            {% endif %}
                            <a class="item" href="{{ url_for('core.auth.logout') }}">
                                <i class="sign out alternate icon"></i>
                                {% trans %}Log out{% endtrans %}
                            </a>
                        {% else %}
                            <a class="item" href="{{ url_for('core.auth.login') }}">
                                <i class="sign in alternate icon"></i>
                                {% trans %}Sign in{% endtrans %}
                            </a>

                        {% endif %}
                    </nav>
                    {% if self.submenu() | trim %}
                        <nav class="ui bottom attached equal width borderless menu">
                            {% block submenu %}{% endblock %}
                        </nav>
                    {% endif %}
                </div>
            {% endif %}
        {% endblock %}


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

        <footer>
            <a href="{{ url_for('core.account.about') }}">{{ _("About Canaille") }}</a>
        </footer>
        {% if config["CANAILLE"]["JAVASCRIPT"] %}
            {% if not is_boosted %}
                <script src="{{ url_for("static", filename="jquery/jquery.min.js") }}" defer></script>
                <script src="{{ url_for("static", filename="fomanticui/semantic.min.js") }}" defer></script>
                {% if config["CANAILLE"]["HTMX"] %}
                    <script src="{{ url_for("static", filename="htmx/htmx.min.js") }}" defer></script>
                    <script>
                        document.addEventListener('DOMContentLoaded', function() {
                            htmx.config.requestClass = "loading"
                        })
                    </script>
                {% endif %}
                <script src="{{ url_for("static", filename="js/base.js") }}" defer></script>
            {% endif %}
            {% block script %}{% endblock %}
        {% endif %}
    </body>
</html>
