{% load i18n %}
{% load helper_tags %}
<nav class="sticky-top navbar navbar-expand-lg navbar-dark bg-dark">
    <div class="container-fluid">
        <a class="navbar-brand" href="{% url 'start:index' %}">
            <img src="https://static.cscherr.de/images/profile/profile-margin.png" alt="Logo" height="30" class="d-inline-block align-text-top">
            {% translate "cscherr.de" noop %}
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                <li class="nav-item">
                    <a class="nav-link" aria-current="page" href="{% url 'start:index' %}">{% translate "Start" %}</a>
                </li>
                <li class="nav-item">
                    <a class="nav-link" href="{% url 'blog:index' %}">{% translate "Blog" %}</a>
                </li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        Debug
                    </a>
                    <ul class="dropdown-menu">
                        <li><a class="dropdown-item" href="http://localhost:8082" target="_blank">DB</a></li>
                        <li><a class="dropdown-item" href="{% url 'admin:index' %}" target="_blank">Admin</a></li>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="#">Something else here</a></li>
                    </ul>
                </li>
                <li class="nav-item dropdown">
                    {% get_available_languages as languages %}
                    <a class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-expanded="false">
                        {{ LANGUAGE_CODE }}
                    </a>
                    <ul class="dropdown-menu">
                        {% for lang_code, lang_name in languages %}
                        <li><a class="dropdown-item" 
                               href="{{ request.scheme }}://{{ request.META.HTTP_HOST }}{% change_lang lang_code %}?{{ request.GET.urlencode }}">
                                {{ lang_name }}</a></li>
                        {% endfor %}
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="#">Something else here</a></li>
                    </ul>
                </li>
                <li class="nav-item">
                    {% include 'dark_light_switch.html' %}
                </li>
            </ul>
            {% include 'main_search_form.html' %}
        </div>
    </div>
    <script>
        'use strict'
        document.getElementById("toggleThemeButton").onclick = function () { 
            const storedTheme =  localStorage.getItem('theme');
            if (storedTheme == null) {
                localStorage.setItem("theme", "dark");
                document.getElementById("toggleThemeIcon").className = "bi bi-sun";
                setTheme("dark"); 
            }
            else if (storedTheme == "dark") {
                localStorage.setItem("theme", "light");
                document.getElementById("toggleThemeIcon").className = "bi bi-sun-fill";
                setTheme("light");
            }
            else if (storedTheme == "light") {
                localStorage.setItem("theme", "dark");
                document.getElementById("toggleThemeIcon").className = "bi bi-sun";
                setTheme("dark");
            }
        };
    </script>
</nav>
