{% extends "base.html" %}
{% import "macros/views.html" as macros with context %}
{% if (not _is_login_path ) and is_auth_enabled %}
    {% set current_user = (request | get_admin_user) %}
    {% set config = (request | get_admin_config) %}
    {% set logo_url = config.logo_url if config and config.logo_url else logo_url %}
    {% set app_title = config.app_title if config and config.app_title else app_title %}
{% endif %}
{% block body %}
    <div class="page">
        {% block navbar %}
            {% if current_user or i18n_config.language_switcher %}
                <header class="navbar navbar-expand-md navbar-light d-none d-lg-flex d-print-none">
                    <div class="container" style="max-width: 100%">
                        <h1 class="navbar-brand navbar-brand-autodark mr-3">
                            <a class="brand-link" href="{{ url_for(__name__ ~ ':index') }}">
                                {% if logo_url %}
                                <img src="{{ logo_url }}"
                                     class="navbar-logo"/>
                                {% else %}
                                <h3>{{ app_title }}</h3>
                                {% endif %}
                            </a>
                            {{ model.ui.ui_server.title }}
                        </h1>
                        <span class="mx-1"></span>
                        <span class="badge bg-lime text-lime-fg mb-3">{{ model.ui.ui_server.version }}</span>
                        <span class="mx-2"></span>
                        <span class="navbar-text">{{ model.ui.ui_server.description }}</span>
                        <div class="navbar-nav flex-row order-md-last">
                            {% if i18n_config.language_switcher %}
                                <div class="nav-item dropdown">
                                    <button type="button" class="btn dropdown-toggle" data-bs-toggle="dropdown">
                                        <svg xmlns="http://www.w3.org/2000/svg"
                                             class="icon icon-tabler icon-tabler-language"
                                             width="24"
                                             height="24"
                                             viewBox="0 0 24 24"
                                             stroke-width="2"
                                             stroke="currentColor"
                                             fill="none"
                                             stroke-linecap="round"
                                             stroke-linejoin="round">
                                            <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                            <path d="M4 5h7"></path>
                                            <path d="M9 3v2c0 4.418 -2.239 8 -5 8"></path>
                                            <path d="M5 9c-.003 2.144 2.952 3.908 6.7 4"></path>
                                            <path d="M12 20l4 -9l4 9"></path>
                                            <path d="M19.1 18h-6.2"></path>
                                        </svg>
                                        {{ get_locale_display_name(get_locale()) }}
                                    </button>
                                    <div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                                        {% for lang in i18n_config.language_switcher %}
                                            <a href="#"
                                               class="dropdown-item language-switcher-item"
                                               data-lang="{{ lang }}"
                                               data-cookie-name="{{ i18n_config.language_cookie_name }}">{{ get_locale_display_name(lang) }}</a>
                                        {% endfor %}
                                    </div>
                                </div>
                            {% endif %}
                            {% if current_user %}
                                <div class="nav-item dropdown ms-3">
                                    <a href="#"
                                       class="nav-link d-flex lh-1 text-reset p-0"
                                       data-bs-toggle="dropdown"
                                       aria-label="Open user menu">
                                        <span class="avatar avatar-sm"
                                                {% if current_user.photo_url %}
                                              style="background-image: url({{ current_user.photo_url }})"{% endif %}>
                                            {% if not current_user.photo_url %}
                                                <svg xmlns="http://www.w3.org/2000/svg"
                                                     class="icon icon-tabler icon-tabler-user"
                                                     width="24"
                                                     height="24"
                                                     viewBox="0 0 24 24"
                                                     stroke-width="2"
                                                     stroke="currentColor"
                                                     fill="none"
                                                     stroke-linecap="round"
                                                     stroke-linejoin="round">
                                                    <path stroke="none" d="M0 0h24v24H0z" fill="none"></path>
                                                    <circle cx="12" cy="7" r="4"></circle>
                                                    <path d="M6 21v-2a4 4 0 0 1 4 -4h4a4 4 0 0 1 4 4v2"></path>
                                                </svg>
                                            {% endif %}
                                        </span>
                                        <div class="ps-2">
                                            <div>{{ current_user.username }}</div>
                                        </div>
                                    </a>
                                    <div class="dropdown-menu dropdown-menu-end dropdown-menu-arrow">
                                        <a href="{{ request.url_for(__name__ ~ ':logout') }}"
                                           class="dropdown-item">{{ _("Logout") }}</a>
                                    </div>
                                </div>
                            {% endif %}
                        </div>
                        <div class="collapse navbar-collapse" id="navbar-menu">
                        </div>
                    </div>
                </header>
            {% endif %}
        {% endblock %}
        <div class="page-wrapper">
            <div class="container-fluid">
                {% block page_header %}
                <div class="page-header d-print-none"></div>
                {% endblock %}
            </div>
            <div class="page-body flex-grow-1">
                <div class="container-fluid">
                    <div class="row row-deck row-cards">
                        {% block content %}{% endblock %}
                    </div>
                </div>
            </div>
        </div>
        {% block footer %}
        <footer class="footer">
            <div class="container">
                <div class="py-1 text-center">
                    <a href="{{ model.ui.ui_server.terms_of_service }}">Terms of service</a>
                    <span class="mx-2">|</span>
                    <a href="mailto:{{ model.ui.ui_server.contact['email'] }}">{{ model.ui.ui_server.contact['name'] }}</a>
                    <span class="mx-2">|</span>
                    <a href="mailto:{{ model.ui.ui_server.license_info['url'] }}">{{ model.ui.ui_server.license_info['name'] }}</a>
                </div>
            </div>
        </footer>
        {% endblock %}
    </div>

{% endblock %}
