{% load static i18n pretty_money static getenv perms memberinfo %}
{% comment %}
SPDX-License-Identifier: GPL-3.0-or-later
{% endcomment %}
<!DOCTYPE html>
{% get_current_language as LANGUAGE_CODE %}{% get_current_language_bidi as LANGUAGE_BIDI %}
<html lang="{{ LANGUAGE_CODE|default:"en" }}" {% if LANGUAGE_BIDI %}dir="rtl"{% endif %} class="position-relative h-100">
{% if not config.MAINTENANCE %}
<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="{% static "bootstrap4/css/bootstrap.min.css" %}">
    <link rel="stylesheet" href="{% static "font-awesome/css/font-awesome.min.css" %}">
    <link rel="stylesheet" href="{% static "css/custom.css" %}">
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/intl-tel-input@25.5.2/build/css/intlTelInput.css">

    {# JQuery, Bootstrap and Turbolinks JavaScript #}
    <script src="{% static "jquery/jquery.min.js" %}"></script>
    <script src="{% static "popper.js/umd/popper.min.js" %}"></script>
    <script src="{% static "bootstrap4/js/bootstrap.min.js" %}"></script>
    <script src="{% static "js/turbolinks.js" %}"></script>
    <script src="{% static "js/base.js" %}"></script>
    <script src="{% static "js/konami.js" %}"></script>

    {# Translation in javascript files #}
    <script src="{% static "js/jsi18n/"|add:LANGUAGE_CODE|add:".js" %}"></script>

    <script src="https://cdn.jsdelivr.net/npm/intl-tel-input@25.5.2/build/js/intlTelInput.min.js"></script>
    
    {# If extra ressources are needed for a form, load here #}
    {% 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-lg 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">
                            {% url 'note:consos' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-coffee"></i> {% trans 'Consumptions' %}</a>
                        </li>
                    {% endif %}
                    {% if request.user.is_authenticated %}
                        <li class="nav-item">
                            {% url 'food:food_list' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-cutlery"></i> {% trans 'Food' %}</a>
                        </li>
                    {% endif %}
                    {% if user.is_authenticated %}
                        <li class="nav-item">
                            {% url 'note:transfer' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-exchange"></i> {% trans 'Transfer' %}</a>
                        </li>
                    {% endif %}
                    {% if user.is_authenticated %}
                        <li class="nav-item">
                            {% url 'family:family_list' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-home"></i> {% trans 'Families' %}</a>
                        </li>
                    {% endif %}

                    {% if "auth.user"|model_list_length >= 2 %}
                        <li class="nav-item">
                            {% url 'member:user_list' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-user"></i> {% trans 'Users' %}</a>
                        </li>
                    {% endif %}
                    {% if "member.club"|not_empty_model_list %}
                        <li class="nav-item">
                            {% url 'member:club_list' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-users"></i> {% trans 'Clubs' %}</a>
                        </li>
                    {% endif %}
                    {% if "activity.activity"|not_empty_model_list %}
                        <li class="nav-item">
                            {% url 'activity:activity_list' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-calendar"></i> {% trans 'Activities' %}</a>
                        </li>
                    {% endif %}
                    {% if "treasury.invoice"|not_empty_model_list %}
                        <li class="nav-item">
                            {% url 'treasury:invoice_list' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-credit-card"></i> {% trans 'Treasury' %}</a>
                        </li>
                    {% endif %}
                    {% if "wei.weiclub"|not_empty_model_list %}
                        <li class="nav-item">
                            {% url 'wei:current_wei_detail' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-bus"></i> {% trans 'WEI' %}</a>
                        </li>
		    {% endif %}
		    {% if "wrapped.wrapped"|model_list_length >= 1 %}
			<li class="nav-item">
			    {% url 'wrapped:wrapped_list' as url %}
			    <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa fa-gift"></i> {% trans 'Wrapped' %}</a>
			</li>
                    {% endif %}
                    {% if request.user.is_authenticated %}
                        <li class="nav-item">
                            {% url 'permission:rights' as url %}
                            <a class="nav-link {% if request.path_info == url %}active{% endif %}" href="{{ url }}"><i class="fa 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="fa fa-cogs"></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="fa 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="fa fa-user"></i> {% trans "My account" %}
                                </a>
				<form method="post" action="{% url 'logout' %}">
				    {% csrf_token %}
				    <button class="dropdown-item" type=submit">
					<i class="fa fa-sign-out"></i> {% trans "Log out" %}
				    </button>
                                </form>
                            </div>
                        </li>
                    {% else %}
                {% if request.path != "/registration/signup/" %}
                            <li class="nav-item">
                                <a class="nav-link" href="{% url 'registration:signup' %}">
                                    <i class="fa fa-user-plus"></i> {% trans "Sign up" %}
                                </a>
                            </li>
                        {% endif %}
                {% if request.path != "/accounts/login/" %}
                            <li class="nav-item">
                                <a class="nav-link" href="{% url 'login' %}">
                                    <i class="fa fa-sign-in"></i> {% trans "Log in" %}
                                </a>
                            </li>
                        {% endif %}
                    {% endif %}
                </ul>
            </div>
        </div>
    </nav>
    <div class="{% block containertype %}container{% endblock %} my-3">
	<div id="messages">
            {% if user.is_authenticated %}
                {% if not user|is_member:"BDE" %}
                    <div class="alert alert-danger">
                        {% trans "You are not a BDE member anymore. Please renew your membership if you want to use the note." %}
                    </div>
                {% endif %}

                {% if not 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 %}
            {% endif %}
            {% if user.sogecredit and not user.sogecredit.valid %}
                <div class="alert alert-info">
                    {% blocktrans trimmed %}
                    You declared that you opened a bank account in the Société générale. The bank did not validate
                        the creation of the account to the BDE, so the membership and the WEI are not paid yet.
                        This verification procedure may last a few days.
                        Please make sure that you go to the end of the account creation.
                    {% endblocktrans %}
                </div>
            {% endif %}
	    {% if config.BANNER_MESSAGE and user.is_authenticated %}
	    <div class="alert alert-{{ config.BANNER_TYPE }}">
	      {{ config.BANNER_MESSAGE }}
	    </div>
	    {% endif %}
        </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">{% trans "Contact us" %}</a> &mdash;
                        <a href="mailto:{{ "SUPPORT_EMAIL" | getenv }}"
                           class="text-muted">{% trans "Technical Support" %}</a> &mdash;
                        <a href="https://perso.crans.org/club-bde/charte_informatique.pdf"
                           class="text-muted">{% trans "Charte Info (FR)" %}</a> &mdash;
                        <a href="https://note.crans.org/doc/faq/"
                           class="text-muted">{% trans "FAQ (FR)" %}</a> &mdash;
		   	<a href="https://bde.ens-cachan.fr"
			   class="text-muted">{% trans "Managed by BDE" %}</a> &mdash;
		   	<a href="https://crans.org"
			   class="text-muted">{% trans "Hosted by Cr@ns" %}</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 %}
                        {% for lang_code, lang_name in LANGUAGES %}
                            <option value="{{ lang_code }}"
                                    {% if lang_code == LANGUAGE_CODE %}
                                    selected{% endif %}>
                                {{ lang_name }} ({{ lang_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>
{% endif %}
{% if config.MAINTENANCE %}
<body>
  <div style="text-align:center">
    <br />
    {% trans "The note is not available for now" %}<br /><br />
    {{ config.MAINTENANCE_MESSAGE }}<br /><br />
    {% trans "Thank you for your understanding -- The Respos Info of BDE" %}
  </div>
</body>
{% endif %}
</html>
