{% load static i18n pretty_money static getenv perms %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
<!DOCTYPE html>
<html lang="{{ LANGUAGE_CODE|default:"en" }}" class="position-relative h-100">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <title>
        {% block title %}{{ title }}{% endblock title %} - {{ request.site.name }}
    </title>
    <meta name="description" content="{% trans "The ENS Paris-Saclay BDE note." %}">

    {# 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">

    {# Bootstrap, Font Awesome and custom CSS #}
    <link rel="stylesheet"
          href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
          integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
          crossorigin="anonymous">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/v4-shims.css">
    <link rel="stylesheet" href="{% static "css/custom.css" %}">

    {# JQuery, Bootstrap and Turbolinks JavaScript #}
    <script src="https://code.jquery.com/jquery-3.4.1.min.js"
            integrity="sha384-vk5WoKIaW/vJyUAd9n/wmopsmNhiy+L2Z+SBxGYnUkunIxVxAv/UtMOhba/xskxh"
            crossorigin="anonymous"></script>
    <script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"
            integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
            crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
            integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
            crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/turbolinks/5.2.0/turbolinks.js"
            crossorigin="anonymous"></script>
    <script src="{% static "js/base.js" %}"></script>

    {# Si un formulaire requiert des données supplémentaires (notamment JS), les données sont chargées #}
    {% if form.media %}
        {{ form.media }}
    {% endif %}

    {% block extracss %}{% endblock %}
</head>
<body class="d-flex w-100 h-100 flex-column">
<main class="mb-auto">
    <nav class="navbar navbar-expand-md navbar-dark bg-primary fixed-navbar shadow-sm">
        <div class="container-fluid">
            <a class="navbar-brand" href="/">{{ request.site.name }}</a>
            <button class="navbar-toggler" type="button" data-toggle="collapse"
                    data-target="#navbarNavDropdown"
                    aria-controls="navbarNavDropdown" aria-expanded="false"
                    aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNavDropdown">
                <ul class="navbar-nav">
                    {% if "note.transactiontemplate"|not_empty_model_list %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'note:consos' %}"><i class="fas fa-coffee"></i> {% trans 'Consumptions' %}</a>
                        </li>
                    {% endif %}
                    {% if "note.transaction"|not_empty_model_list %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'note:transfer' %}"><i class="fas fa-exchange-alt"></i> {% trans 'Transfer' %} </a>
                        </li>
                    {% endif %}
                    {% if "auth.user"|model_list_length >= 2 %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'member:user_list' %}"><i class="fas fa-user"></i> {% trans 'Users' %}</a>
                        </li>
                    {% endif %}
                    {% if "member.club"|not_empty_model_list %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'member:club_list' %}"><i class="fas fa-users"></i> {% trans 'Clubs' %}</a>
                        </li>
                    {% endif %}
                    {% if "activity.activity"|not_empty_model_list %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'activity:activity_list' %}"><i class="fas fa-calendar"></i> {% trans 'Activities' %}</a>
                        </li>
                    {% endif %}
                    {% if "treasury.invoice"|not_empty_model_list %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'treasury:invoice_list' %}"><i class="fas fa-credit-card"></i> {% trans 'Treasury' %}</a>
                        </li>
                    {% endif %}
                    {% if "wei.weiclub"|not_empty_model_list %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'wei:current_wei_detail' %}"><i class="fas fa-bus"></i> {% trans 'WEI' %}</a>
                        </li>
                    {% endif %}
                    {% if request.user.is_authenticated %}
                        <li class="nav-item">
                            <a class="nav-link" href="{% url 'permission:rights' %}"><i class="fas fa-balance-scale"></i> {% trans 'Rights' %}</a>
                        </li>
                    {% endif %}
                    {% if request.user.is_staff and ""|has_perm:user %}
                        <li class="nav-item">
                            <a data-turbolinks="false" class="nav-link" href="{% url 'admin:index' %}"><i class="fas fa-user-cog"></i> {% trans 'Admin' %}</a>
                        </li>
                    {% endif %}
                </ul>
                <ul class="navbar-nav ml-auto">
                    {% if request.user.is_authenticated %}
                        <li class="dropdown">
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                                <i class="fas fa-user"></i>
                                <span id="user_balance">{{ request.user.username }} ({{ request.user.note.balance | pretty_money }})</span>
                            </a>
                            <div class="dropdown-menu dropdown-menu-right"
                                 aria-labelledby="navbarDropdownMenuLink">
                                <a class="dropdown-item" href="{% url 'member:user_detail' pk=request.user.pk %}">
                                    <i class="fas fa-user"></i> Mon compte
                                </a>
                                <a class="dropdown-item" href="{% url 'logout' %}">
                                    <i class="fas fa-sign-out-alt"></i> Se déconnecter
                                </a>
                            </div>
                        </li>
                    {% else %}
                {% if request.path != "/registration/signup/" %}
                            <li class="nav-item">
                                <a class="nav-link" href="{% url 'registration:signup' %}">
                                    <i class="fas fa-user-plus"></i> S'inscrire
                                </a>
                            </li>
                        {% endif %}
                {% if request.path != "/accounts/login/" %}
                            <li class="nav-item">
                                <a class="nav-link" href="{% url 'login' %}">
                                    <i class="fas fa-sign-in-alt"></i> Se connecter
                                </a>
                            </li>
                        {% endif %}
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>
    <div class="{% block containertype %}container{% endblock %} my-3">
        {% if request.user.is_authenticated and not request.user.profile.email_confirmed %}
            <div class="alert alert-warning">
                {% trans "Your e-mail address is not validated. Please check your mail inbox and click on the validation link." %}
            </div>
        {% endif %}
        {% block contenttitle %}<h1 class="text-white">{{ title }}</h1>{% endblock %}
        <div class="alert alert-warning alert-dismissible">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&#215;</button>
            Attention : la Note Kfet 2020 est en phase de beta. Des fonctionnalités pourront être rajoutées d'ici à la version
            finale, et des bugs peuvent survenir. Pour tout problème, merci d'envoyer un mail à l'adresse
            <a href="mailto:&#110;&#111;&#116;&#101;&#107;&#102;&#101;&#116;&#50;&#48;&#50;&#48;&commat;&#108;&#105;&#115;&#116;&#115;&period;&#99;&#114;&#97;&#110;&#115;&period;&#111;&#114;&#103;">
                &#110;&#111;&#116;&#101;&#107;&#102;&#101;&#116;&#50;&#48;&#50;&#48;&commat;&#108;&#105;&#115;&#116;&#115;&period;&#99;&#114;&#97;&#110;&#115;&period;&#111;&#114;&#103;</a>,
            ou bien levez une issue sur le dépôt <a href="https://gitlab.crans.org/bde/nk20/-/issues">Gitlab</a>,
            ou encore posez un commentaire sur le <a href="https://pad.crans.org/p/todoNK20">pad</a>.<br><br>

            Certaines données ont été anonymisées afin de limiter les fuites de données, et peuvent ne pas correspondre avec vos données réelles.
        </div>
        <div id="messages"></div>
        {% block content %}
            <p>Default content...</p>
        {% endblock %}
    </div>
</main>
<footer class="bg-dark text-white mt-auto py-2">
    <div class="container-fluid">
        <div class="row">
            <div class="col-10">
                <form action="{% url 'set_language' %}" method="post"
                      class="form-inline">
                    <span class="text-muted mr-1">
                        <a href="mailto:{{ "CONTACT_EMAIL" | getenv }}"
                           class="text-muted">Nous contacter</a> &mdash;
                    </span>
                    {% csrf_token %}
                    <select title="language" name="language"
                            class="form-control form-control-sm 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>
            </div>
            <div class="col text-right">
                <a href="#" data-turbolinks="false" class="text-muted">
                    <i class="fa fa-arrow-up" aria-hidden="true"></i>
                </a>
            </div>
        </div>
    </div>
</footer>

<script>
    CSRF_TOKEN = "{{ csrf_token }}";
    $(".invalid-feedback").addClass("d-block");
</script>

{% block extrajavascript %}{% endblock %}
</body>
</html>