<% if (user?.admin){ %>
<div class="admin-bar">
  <a href="/admin" class="admin-bar">Click here to reach admin panel</a>
</div>
<% } %>


<nav class="navbar navbar-expand-lg navbar-light bg-light">
  <div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarText" aria-controls="navbarText" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <a class="navbar-brand" href="/"><%= dataset.forum_name.toUpperCase() %></a>

    <div class="collapse navbar-collapse" id="navbarText">
      <ul class="navbar-nav me-auto mb-2 mb-lg-0">

        <li class="nav-item">
          <a class="nav-link" href="/threads/create/">Create Thread</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="/categories">Categories</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="/threads">Threads</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="/users">Users</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="/search">Search</a>
        </li>

        <li class="nav-item">
          <a class="nav-link" href="/login">Logout</a>
        </li>
      </ul>

    </div>
    <div>
      <% if (user) { %>
      <a class="navbar-brand" href="<%=user.getLink()%>"> <%=  user.name %>
        <img style="border-radius: 50%;" width="32" src="<%=user.avatar %>">
      </a>

      <% } else{ %>
      <a class="navbar-brand" id="login" href="/login">Login</a>
      <script>
        document.getElementById("login").href += "?redirect=" + location.pathname;
      </script>
      <% } %>
    </div>
  </div>
  <script>
    const menuItems = document.getElementsByClassName("nav-link");

    for (let i = 0; i < menuItems.length; i++) 
      if (window.location.pathname.includes(menuItems[i].getAttribute("href"))) {
        menuItems[i].classList.add("active");
        break;
      }
    
  </script>

</nav>