{% load static %}
{% load i18n %}
{% load theming_tags %}
{% load custom_tags %}

<html>
<head>
    <title>{% block title %}
    {% endblock %}</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="noindex,nofollow"/>


    <link rel="shortcut icon" type="image/x-icon" href="{% static 'assets/favicon.svg' %}">
    <link rel="shortcut icon" href="{% static 'assets/favicon.svg' %}">
    <link rel="icon" type="image/png" href="{% static 'assets/favicon-32x32.png' %}" sizes="32x32">
    <link rel="icon" type="image/png" href="{% static 'assets/favicon-16x16.png' %}" sizes="16x16">

    <link rel="mask-icon" href="{% static 'assets/safari-pinned-tab.svg' %}" color="#161616">
    <link rel="apple-touch-icon" href="{% static 'assets/apple-touch-icon.png' %}" sizes="180x180">

    <link rel="manifest" crossorigin="use-credentials" href="{% url 'web_manifest' %}">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">


    <link rel="mask-icon" href="/safari-pinned-tab.svg" color="#161616">
    <meta name="msapplication-TileColor" content="#161616">
    <meta name="theme-color" content="#ffffff">


    <!-- Bootstrap 4 -->
    <link id="id_main_css" href="{% theme_url request %}" rel="stylesheet">
    <link href="{% static 'css/app.min.css' %}" rel="stylesheet">
    <script src="{% static 'js/jquery-3.5.1.min.js' %}"></script>

    <script src="{% static 'js/popper.min.js' %}"></script>
    <script src="{% static 'js/bootstrap.min.js' %}"></script>

    <!-- Select2 for use with django autocomplete light -->
    <link href="{% static 'css/select2.min.css' %}" rel="stylesheet"/>
    <script src="{% static 'js/select2.min.js' %}"></script>

    <!-- Bootstrap theme for select2 -->
    <link rel="stylesheet" href="{% static 'css/select2-bootstrap.css' %}"/>

    <link rel="stylesheet" href="{% static 'themes/select2-bootstrap-theme.css' %}"/>

    <script type="text/javascript">
        $.fn.select2.defaults.set("theme", "bootstrap");
        {% if request.user.is_authenticated %}
            window.ACTIVE_SPACE_ID = '{{request.space.id}}';
        {% endif %}
    </script>

    <!-- Fontawesome icons -->
    <link rel="stylesheet" href="{% static "fontawesome/fontawesome_all.min.css" %}">

    {% block extra_head %} <!-- block for templates to put stuff into header -->
    {% endblock %}

    <style>
        {% if request.user.userpreference.left_handed %}
            @media screen and (max-width: 600px) {
                #switcher .btn-circle {
                    left: 80px !important;
                }
            }
        {% endif %}
    </style>

</head>
<body>

<nav class="navbar navbar-expand-lg {% nav_color request %}"
     id="id_main_nav"
     style="{% sticky_nav request %}">

    {% if not request.user.userpreference.left_handed %}
        {% if not request.user.is_authenticated or request.user.userpreference.theme == request.user.userpreference.TANDOOR %}
            <a class="navbar-brand p-0 me-2 justify-content-center" href="{% base_path request 'base' %}"
               aria-label="Tandoor">
                <img class="brand-icon" src="{% static 'assets/brand_logo.png' %}" alt="Logo">
            </a>
        {% endif %}
    {% endif %}

    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarText"
            aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>

    {% if request.user.userpreference.left_handed %}
        {% if not request.user.is_authenticated or request.user.userpreference.theme == request.user.userpreference.TANDOOR %}
            <a class="navbar-brand p-0 me-2 justify-content-center" href="{% base_path request 'base' %}"
               aria-label="Tandoor">
                <img class="brand-icon" src="{% static 'assets/brand_logo.png' %}" alt="Logo">
            </a>
        {% endif %}
    {% endif %}

    <div class="collapse navbar-collapse" id="navbarText">
        <ul class="navbar-nav mr-auto">
            <li class="nav-item {% if request.resolver_match.url_name in 'view_search' %}active{% endif %}">
                <a class="nav-link" href="{% url 'view_search' %}"><i
                        class="fas fa-fw fa-book"></i> {% trans 'Recipes' %}</a>
            </li>
            <li class="nav-item {% if request.resolver_match.url_name in 'view_plan' %}active{% endif %}">
                <a class="nav-link" href="{% url 'view_plan' %}"><i
                        class="fas fa-fw fa-calendar"></i> {% trans 'Meal-Plan' %}</a>
            </li>
            <li class="nav-item {% if request.resolver_match.url_name in 'list_shopping_list,view_shopping' %}active{% endif %}">
                <a class="nav-link" href="{% url 'list_shopping_list' %}"><i
                        class="fas fa-fw fa-shopping-cart"></i> {% trans 'Shopping' %}</a>
            </li>
            <li class="nav-item {% if request.resolver_match.url_name in 'view_books' %}active{% endif %}">
                <a class="nav-link" href="{% url 'view_books' %}"><i
                        class="fas fa-fw fa-book-open"></i> {% trans 'Books' %}</a>
            </li>
            {% plugin_main_nav_templates as plugin_main_nav_templates %}
            {% for pn in plugin_main_nav_templates %}
                {% include pn %}
            {% endfor %}
        </ul>

        <ul class="navbar-nav ml-auto">
            {% if user.is_authenticated %}
                {% page_help request.resolver_match.url_name as help_button %}
                {% if help_button %}{{ help_button|safe }}{% endif %}

                <li class="nav-item dropdown {% if request.resolver_match.url_name in 'list_keyword,list_food,list_unit,view_supermarket,data_batch_edit,view_history' %}active{% endif %}">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false">
                        <i class="fas fa-fw fa-toolbox fa-lg"></i>
                    </a>
                    <div class="dropdown-menu dropdown-menu-center dropdown-menu-center-large">
                        <div class="row m-0 mt-2 mt-md-0">
                            <div class="col-4">
                                <a href="{% url 'list_keyword' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-tags fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Keyword' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div class="col-4">
                                <a href="{% url 'list_food' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-leaf fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Foods' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div class="col-4">
                                <a href="{% url 'list_unit' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-balance-scale fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Units' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                        </div>
                        <div class="row m-0 mt-2 mt-md-0">
                            <div class="col-4">
                                <a href="{% url 'list_supermarket' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-store-alt fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Supermarket' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div class="col-4">
                                <a href="{% url 'list_supermarket_category' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-cubes fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Supermarket Category' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div class="col-4">
                                <a href="{% url 'list_automation' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-robot fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Automations' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                        </div>
                        <div class="row m-0 mt-2 mt-md-0">
                            <div class="col-4">
                                <a href="{% url 'list_user_file' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-file fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Files' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div class="col-4">
                                <a href="{% url 'data_batch_edit' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-edit fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Batch Edit' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div class="col-4">
                                <a href="{% url 'view_history' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-history fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'History' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                        </div>
                        <div class="row m-0 mt-2 mt-md-0">
                            <div class="col-4">
                                <a href="{% url 'view_ingredient_editor' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-th-list fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Ingredient Editor' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div class="col-4">
                                <a href="{% url 'view_export' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-file-export fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Export' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                            <div class="col-4">
                                <a href="{% url 'list_property_type' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-database fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Properties' %}
                                        </div>
                                    </div>
                                </a>
                            </div>
                        </div>
                        <div class="row m-0 mt-2 mt-md-0">
                            <div class="col-4">
                                <a href="{% url 'list_unit_conversion' %}" class="p-0 p-md-1">
                                    <div class="card p-0 no-gutters border-0">
                                        <div class="card-body text-center p-0 no-gutters">
                                            <i class="fas fa-exchange-alt fa-2x"></i>
                                        </div>
                                        <div class="card-body text-break text-center p-0 no-gutters text-muted menu-dropdown-text">
                                            {% trans 'Unit Conversions' %}
                                        </div>
                                    </div>
                                </a>
                            </div>

                        </div>
                    </div>
                </li>
                <li class="nav-item dropdown {% if request.resolver_match.url_name in 'data_import_url,new_recipe' %}active{% endif %}">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false"><i
                            class="fas fa-fw fa-plus fa-lg"></i>
                    </a>
                    <div class="dropdown-menu dropdown-menu-center"
                         aria-labelledby="navbarDropdownMenuLink">
                        <a class="dropdown-item" href="{% url 'data_import_url' %}"><i
                                class="fas fa-file-import"></i> {% trans 'Import Recipe' %}</a>
                        <a class="dropdown-item " href="{% url 'new_recipe' %}"><i
                                class="fas fa-plus"></i> {% trans 'Create' %}</a>
                    </div>
                </li>
                <li class="nav-item dropdown {% if request.resolver_match.url_name in 'view_space,view_settings,view_history,view_system,docs_markdown' %}active{% endif %}">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" data-toggle="dropdown"
                       aria-haspopup="true" aria-expanded="false"><i
                            class="fas fa-fw fa-user-alt"></i> {{ user.get_user_display_name }}
                    </a>

                    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdownMenuLink">
                        <a class="dropdown-item" href="{% url 'view_settings' %}"><i
                                class="fas fa-user-cog fa-fw"></i> {% trans 'Settings' %}</a>
                        <a class="dropdown-item" href="{% url 'data_sync' %}"><i
                                class="fas fa-sync-alt fa-fw"></i> {% trans 'External Recipes' %}</a>
                        {% if request.user == request.space.created_by %}
                            <a class="dropdown-item" href="{% url 'view_space_manage' request.space.pk %}"><i
                                    class="fas fa-server fa-fw"></i> {% trans 'Space Settings' %}</a>
                        {% endif %}
                        {% if user.is_superuser %}
                            <div class="dropdown-divider"></div>
                            <a class="dropdown-item" href="{% url 'view_system' %}"><i
                                    class="fas fa-server fa-fw"></i> {% trans 'System' %}</a>
                            <a class="dropdown-item" href="{% url 'admin:index' %}"><i
                                    class="fas fa-user-shield fa-fw"></i> {% trans 'Admin' %}</a>
                        {% endif %}
                        {% if request.user.is_authenticated %}
                            <div class="dropdown-divider"></div>
                            <h6 class="dropdown-header">{% trans 'Your Spaces' %}</h6>
                            {% for us in request.user.userspace_set.all %}
                                <a class="dropdown-item" href="{% url 'view_switch_space' us.space.id %}">
                                    {% if us.active %}
                                        <i class="far fa-dot-circle fa-fw"></i>
                                    {% else %}
                                        <i class="far fa-circle fa-fw"></i>
                                    {% endif %}
                                    {{ us.space.name }}</a>
                            {% endfor %}
                            <a class="dropdown-item" href="{% url 'view_space_overview' %}"><i
                                    class="fas fa-list"></i> {% trans 'Overview' %}</a>
                        {% endif %}
                        {% plugin_dropdown_nav_templates as plugin_dropdown_nav_templates %}
                        {% for pn in plugin_dropdown_nav_templates %}
                            <div class="dropdown-divider"></div>
                            {% include pn %}
                        {% endfor %}

                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="{% url 'docs_markdown' %}"><i
                                class="fab fa-markdown fa-fw"></i> {% trans 'Markdown Guide' %}</a>
                        <a class="dropdown-item" href="https://github.com/vabene1111/recipes"><i
                                class="fab fa-github fa-fw"></i> {% trans 'GitHub' %}</a>
                        <a class="dropdown-item" href="https://translate.tandoor.dev/projects/tandoor/"><i
                                class="fas fa-language fa-fw"></i> {% trans 'Translate Tandoor' %}</a>
                        <a class="dropdown-item" href="{% url 'docs_api' %}"><i
                                class="fas fa-passport fa-fw"></i> {% trans 'API Documentation' %}</a>
                        <a class="dropdown-item" href="{% url 'api:api-root' %}"><i
                                class="fas fa-file-code fa-fw"></i> {% trans 'API Browser' %}</a>
                        <div class="dropdown-divider"></div>
                        <a class="dropdown-item" href="{% url 'account_logout' %}"><i
                                class="fas fa-sign-out-alt fa-fw"></i> {% trans 'Log out' %}</a>
                    </div>
                </li>
            {% else %}
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'account_login' %}">{% trans 'Login' %} <i
                            class="fas fa-fw fa-sign-in-alt"></i></a>
                </li>
            {% endif %}
        </ul>
    </div>
</nav>


{% message_of_the_day request as message_of_the_day %}
{% if message_of_the_day %}
    <div class="bg-info" style=" width: 100%; text-align: center!important; color: #ffffff; padding: 8px">
        {{ message_of_the_day | markdown |safe }}
    </div>
{% endif %}

{% if HOSTED and request.space.max_recipes == 10 %}
    <div class="bg-warning" style=" width: 100%; text-align: center!important; color: #ffffff; padding: 8px">
        {% trans 'You are using the free version of Tandor' %} <a class="btn-success btn-sm"
                                                                  href="https://tandoor.dev/manage">{% trans 'Upgrade Now' %}</a>
    </div>
{% endif %}

<div class="container-fluid mt-2 mt-md-5 mt-xl-5 mt-lg-5{% if request.user.userpreference.left_handed %} left-handed {% endif %}"
     id="id_base_container">
    <div class="row">
        <div class="col-xl-2 d-none d-xl-block">
            {% block content_xl_left %}

            {% endblock %}
        </div>
        <div class="col-xl-8 col-12">
            {% for message in messages %}
                <div class="row">
                    <div class="col col-md-12">
                        <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                            {{ message }}
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                <span aria-hidden="true">&times;</span>
                            </button>
                        </div>
                    </div>
                </div>
            {% endfor %}

            {% block content %}

            {% endblock %}
        </div>
        <div class="col-xl-2 d-none d-xl-block">
            {% block content_xl_right %}

            {% endblock %}
        </div>
    </div>

    {% block content_fluid %}
    {% endblock %}

    {% user_prefs request as prefs %}
    {{ prefs|json_script:'user_preference' }}

</div>

{% block script %}
{% endblock script %}

<script type="application/javascript">
    localStorage.setItem('SCRIPT_NAME', "{% base_path request 'script' %}")
    localStorage.setItem('BASE_PATH', "{% base_path request 'base' %}")
    localStorage.setItem('STATIC_URL', "{% base_path request 'static_base' %}")
    localStorage.setItem('DEBUG', "{% is_debug %}")
    localStorage.setItem('USER_ID', "{{request.user.pk}}")

    window.addEventListener("load", () => {
        if ("serviceWorker" in navigator) {
            navigator.serviceWorker.register("{% url 'service_worker' %}", {scope: "{% base_path request 'base' %}" + '/'}).then(function (reg) {

            }).catch(function (err) {
                console.warn('Error whilst registering service worker', err);
            });
        } else {
            console.warn('service worker not in navigator');
        }
    });
</script>

<style>
    @media screen and (max-width: 1000px) {
        .navbar-collapse {
            max-height: 60vh;
            overflow-y: auto;
            overflow-x: hidden;
        }

        .collapsing {
            overflow-y: hidden;
            overflow-x: hidden;
        }
    }
</style>

</body>
</html>
