<?php
$current_page = $_SERVER['SCRIPT_NAME'];
$nav = '
  <nav>
    <div class="row_no_margin">
      <div class="site_navigation">
        <ul>
          <li><a href="/index.php"' . ($current_page == '/index.php' ? ' class="underline"' : '') . '>Home</a></li>
          <li><a href="/articles.php"' . ($current_page == '/articles.php' ? ' class="underline"' : '') . '>Articles</a></li>
';

if (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 2) {
  $nav .= '
          <li><a href="/admin.php"' . ($current_page == '/admin.php' ? ' class="underline"' : '') . '>Admin</a></li>
    ';
}

if (isset($_COOKIE['user_id'])) {
  $nav .= '
          <li><a href="/user.php?action=view&user_id=' . $_COOKIE['user_id'] . '"' . ($current_page == '/user.php' ? ' class="underline"' : '') . '>Account</a></li>
    ';
}

if (isset($_COOKIE['role_id']) && $_COOKIE['role_id'] <= 3) {
  $nav .= '
          <li><a href="/compose.php"' . ($current_page == '/compose.php' ? ' class="underline"' : '') . '>Compose</a></li>
    ';
}

$nav .= '
        </ul>
      </div>
      <div class="nav_right_hand">
        <form method="post">
';

$theme_toggle = '';
if ($_SESSION['theme'] == 'dark')
  $theme_toggle = 'light';
else
  $theme_toggle = 'dark';

$nav .= '
          <button id="theme-toggle" value="' . $theme_toggle . '" name="theme" onchange="this.form.submit()"><i class="nf ' . ($theme_toggle == 'dark' ? 'nf-oct-moon' : 'nf-oct-sun') . '"></i></button>
        </form>
';

if (isset($_COOKIE['username'])) {
  $nav .= '
        <a href="user.php?action=logout">Log Out</a>
  ';
} else {
  $nav .= '
        <a href="user.php?action=login">Login</a>
        <a href="user.php?action=signup">Sign Up</a>
  ';
}

$nav .= '
      </div>
    </div>
  </nav>
';

echo $nav;
