{% extends "admin/base.html" %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}

{% load i18n staticfiles %}

{% block title %}{{ title }} | {{ request.site.name }}{% endblock %}

{% block branding %}
    <a href="/">
        <img src="{% static "images/logo.png" %}" height="40px" alt=""/>
        <strong id="site-name">
            {{ request.site.name }}
        </strong>
    </a>
{% endblock %}

{% block usertools %}
    <div id="user-tools">
        {% block welcome-msg %}
            {% if user.is_authenticated %}
                {% trans 'Welcome,' %}
                <strong>{% firstof user.get_short_name user.get_username %}</strong>.
            {% endif %}
        {% endblock %}
        {% block userlinks %}
            {% if available_apps %}
                {# When in admin site, list all admin pages and documentation #}
                <span class="dropdown">
                        <a href="{% url 'admin:index' %}">{% trans 'Explore database' %}</a>
                        <span class="dropdown-content">
                            {% for app in available_apps %}
                                {% for model in app.models %}
                                    {% if model.admin_url %}
                                        <a href="{{ model.admin_url }}">{{ model.name }}</a>
                                    {% endif %}
                                {% endfor %}
                            {% endfor %}
                            <a href="{% url "logs:index" %}">Statistiques</a>
                            {% if user.is_active and user.is_superuser %}
                                {% url 'django-admindocs-docroot' as docsroot %}
                                {% if docsroot %}
                                    <a href="{{ docsroot }}">{% trans 'Documentation' %}</a>
                                {% endif %}
                            {% endif %}
                         </span>
                    </span> /
            {% else %}
                {# When not in admin site, but user is staff then add a link #}
                <a href="{% url 'admin:index' %}">{% trans 'Explore database' %}</a> /
            {% endif %}
            {% if user.is_authenticated %}
                <a href="{% url 'logout' %}">{% trans 'Log out' %}</a>
            {% else %}
                <a href="{% url 'login' %}">{% trans 'Log in' %}</a>
            {% endif %}
        {% endblock %}
    </div>
{% endblock %}

{% block extrastyle %}
    <link rel="stylesheet" type="text/css" href="{% static "css/admin.css" %}"/>

    {# Favicon #}
    <link rel="apple-touch-icon" sizes="180x180" href="{% static "favicon/apple-touch-icon.png" %}">
    <link rel="icon" type="image/png" sizes="32x32" href="{% static "favicon/favicon-32x32.png" %}">
    <link rel="icon" type="image/png" sizes="16x16" href="{% static "favicon/favicon-16x16.png" %}">
    <link rel="manifest" href="{% static "favicon/site.webmanifest" %}">
    <link rel="mask-icon" href="{% static "favicon/safari-pinned-tab.svg" %}" color="#5bbad5">
    <link rel="shortcut icon" href="{% static "favicon/favicon.ico" %}">
    <meta name="msapplication-TileColor" content="#da532c">
    <meta name="msapplication-config" content="{% static "favicon/browserconfig.xml" %}">
    <meta name="theme-color" content="#ffffff">
{% endblock %}

{% block footer %}
    {% if not is_popup %}
        <div id="footer">
            <form action="{% url 'set_language' %}" method="post">
                {% csrf_token %}
                <select title="language" name="language" onchange="this.form.submit()">
                    {% get_current_language as LANGUAGE_CODE %}
                    {% get_available_languages as LANGUAGES %}
                    {% get_language_info_list for LANGUAGES as languages %}
                    {% for language in languages %}
                        <option value="{{ language.code }}"
                                {% if language.code == LANGUAGE_CODE %} selected{% endif %}>
                            {{ language.name_local }} ({{ language.code }})
                        </option>
                    {% endfor %}
                </select>
                <noscript>
                    <input type="submit">
                </noscript>
            </form>
            <p>
                Mediatek 2017-2020 &mdash;
                <a href="mailto:club-med@crans.org">Nous contactez</a> &mdash;
                <a href="{% url "api-root" %}">Explorer l'API</a>
            </p>
        </div>
    {% endif %}

    {# Bind CTRL+S to Save button in forms #}
    <script type="text/javascript">
        if (typeof django !== 'undefined') {
            django.jQuery(window).bind('keydown', function (event) {
                if (event.ctrlKey || event.metaKey) {
                    if (String.fromCharCode(event.which).toLowerCase() === 's') {
                        event.preventDefault();
                        django.jQuery("#content-main form input[name=_save]").click();
                    }
                }
            });
        }
    </script>
{% endblock %}