{% load i18n static %}

<nav class="navbar navbar-expand-lg fixed-navbar shadow-sm">
    <div class="container-fluid">
    <a class="navbar-brand" href="{{ TFJM.HOME_PAGE_LINK }}">
        <img src="{% static TFJM.LOGO_PATH %}" style="height: 2em;" alt="Logo {{ TFJM.APP_NAME }}" id="navbar-logo">
    </a>
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
            data-bs-target="#navbarNavDropdown"
            aria-controls="navbarNavDropdown" aria-expanded="false"
            aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    </button>
    <div id="navbarNavDropdown" class="collapse navbar-collapse">
        <ul class="navbar-nav">
            <li class="nav-item active">
                <a href="{% url "index" %}" class="nav-link"><i class="fas fa-home"></i> {% trans "Home" %}</a>
            </li>
            <li class="nav-item active">
                {% if TFJM.SINGLE_TOURNAMENT %}
                    <a href="{% url 'participation:tournament_detail' pk=TFJM_TOURNAMENT.pk %}" class="nav-link">
                        <i class="fas fa-calendar-day"></i> {% trans "Tournament" %}
                    </a>
                {% else %}
                    <a href="#" class="nav-link" data-bs-toggle="modal" data-bs-target="#tournamentListModal">
                        <i class="fas fa-calendar-day"></i> {% trans "Tournaments" %}
                    </a>
                {% endif %}
            </li>
            {% if user.is_authenticated and user.registration.is_admin %}
                <li class="nav-item active">
                    <a href="{% url "registration:user_list" %}" class="nav-link"><i class="fas fa-user"></i> {% trans "Users" %}</a>
                </li>
                <li class="nav-item active">
                    <a href="{% url "participation:team_list" %}" class="nav-link"><i class="fas fa-users"></i> {% trans "Teams" %}</a>
                </li>
            {% elif user.is_authenticated and user.registration.participates %}
                {% if not user.registration.team %}
                    <li class="nav-item active">
                        <a href="#" class="nav-link" data-bs-toggle="modal" data-bs-target="#createTeamModal">
                            <i class="fas fa-users"></i> {% trans "Create team" %}
                        </a>
                    </li>
                    <li class="nav-item active">
                        <a href="#" class="nav-link" data-bs-toggle="modal" data-bs-target="#joinTeamModal">
                            <i class="fas fa-users"></i> {% trans "Join team" %}
                        </a>
                    </li>
                {% else %}
                    <li class="nav-item active">
                        <a href="{% url "participation:my_team_detail" %}" class="nav-link">
                            <i class="fas fa-users"></i> {% trans "My team" %}
                        </a>
                    </li>
                    <li class="nav-item active">
                        <a href="{% url "participation:my_participation_detail" %}" class="nav-link">
                            <i class="fas fa-file-pdf"></i> {% trans "My participation" %}
                        </a>
                    </li>
                {% endif %}
            {% endif %}
            {% if user.is_authenticated %}
                {% if user.registration.is_volunteer or user.registration.team %}
                    <li class="nav-item active">
                        <a class="nav-link" href="{% url 'draw:index' %}">
                            <i class="fas fa-archive"></i> {% trans "Draw" %}
                        </a>
                    </li>
                {% endif %}
                <li class="nav-item active">
                    <a class="nav-link" href="{% url "chat:chat" %}">
                        <i class="fas fa-comments"></i> {% trans "Chat" %}
                    </a>
                </li>
            {% endif %}
            {% if user.registration.is_admin %}
                <li class="nav-item active">
                    <a class="nav-link" href="{% url "survey:survey_list" %}"><i class="fas fa-square-poll-horizontal"></i> {% trans "surveys"|capfirst %}</a>
                </li>
                <li class="nav-item active">
                    <a class="nav-link" href="{% url "admin:index" %}"><i class="fas fa-cog"></i> {% trans "Administration" %}</a>
                </li>
            {% endif %}
        </ul>
        <ul class="navbar-nav ms-auto">
            {% if user.registration.is_admin %}
                <form class="navbar-form d-flex" role="search" onsubmit="event.preventDefault()">
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="{% trans "Search…" %}" name="q" id="search-term" value="{{ request.GET.q }}">
                        <div class="input-group-btn">
                            <button class="btn btn-default" data-bs-toggle="modal" data-bs-target="#searchModal"><i class="fa fa-search text-body"></i></button>
                        </div>
                    </div>
                </form>
            {% endif %}
            {% if "_fake_user_id" in request.session %}
                <li class="nav-item active">
                    <a class="nav-link" href="{% url "registration:reset_admin" %}?path={{ request.path }}"><i class="fas fa-tools"></i> {% trans "Return to admin view" %}</a>
                </li>
            {% endif %}
            {% if not user.is_authenticated %}
                {% now "c" as now %}
                {% if TFJM.REGISTRATION_DATES.open.isoformat <= now and now <= TFJM.REGISTRATION_DATES.close.isoformat %}
                    <li class="nav-item active">
                        <a class="nav-link" href="{% url "registration:signup" %}"><i class="fas fa-user-plus"></i> {% trans "Register" %}</a>
                    </li>
                {% endif %}
                <li class="nav-item active">
                    <a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#loginModal">
                        <i class="fas fa-sign-in-alt"></i> {% trans "Log in" %}
                    </a>
                </li>
            {% else %}
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink"
                       data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                        <i class="fas fa-user"></i> {{ user.first_name }} {{ user.last_name }}
                    </a>
                    <ul class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdownMenuLink">
                        <li>
                            <a class="dropdown-item" href="{% url "registration:my_account_detail" %}">
                                <i class="fas fa-user"></i> {% trans "My account" %}
                            </a>
                        </li>
                        <li>
                            <form action="{% url 'logout' %}" method="post">
                                {% csrf_token %}
                                <button class="dropdown-item">
                                    <i class="fas fa-sign-out-alt"></i> {% trans "Log out" %}
                                </button>
                            </form>
                        </li>
                    </ul>
                </li>
            {% endif %}
        </ul>
    </div>
    </div>
</nav>