<?php
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
?>

<!--
Globales Menü, wird via PHP später in alle Seiten eingebunden
-->
<nav class="nav">
    <div class="nav__left">
        <a href="index.php" class="nav__logo">
            <img src="images/logos/logo_full.png" alt="Logo">
        </a>
    </div>

    <!-- Mobile navbar mit Burger-Symbol -->
    <input type="checkbox" id="nav-toggle" class="nav__checkbox">
    <label for="nav-toggle" id="mobile-nav">
        <span>☰</span>
    </label>

    <ul id="mobile-nav" class="nav__mobile-menu">
        <li>
            <label for="nav-toggle" class="nav__close-btn">&times;</label>
        </li>

        <?php if (isset($_SESSION['user'])): ?>

            <li><a href="index.php?pfad=profile">Profil</a></li>
            <li>
                <form method="post" action="php/controller/logout-controller.php" class="nav__logout-form">
                    <?php csrf_field(); ?>
                    <button type="submit" class="nav__mobile-logout-button">Abmelden</button>
                </form>
            </li>
            <li><a href="index.php?pfad=createArticle">Beitrag erstellen</a></li>

        <?php else: ?>

            <li><a href="index.php?pfad=login">Anmelden</a></li>
            <li><a href="index.php?pfad=register">Registrieren</a></li>

        <?php endif; ?>

        <li>
            <label class="nav__mobile-label">Sprachen</label>
            <ul class="nav__mobile-submenu">
                <li><a href="index.php?pfad=showCategory&category=deutsch">Deutsch</a></li>
                <li><a href="index.php?pfad=showCategory&category=englisch">Englisch</a></li>
                <li><a href="index.php?pfad=showCategory&category=franzoesisch">Französisch</a></li>
                <li><a href="index.php?pfad=showCategory&category=latein">Latein</a></li>
                <li><a href="index.php?pfad=showCategory&category=literatur">Literatur</a></li>
            </ul>
        </li>

        <li>
            <label class="nav__mobile-label">MINT</label>
            <ul class="nav__mobile-submenu">
                <li><a href="index.php?pfad=showCategory&category=mathe">Mathematik</a></li>
                <li><a href="index.php?pfad=showCategory&category=biologie">Biologie</a></li>
                <li><a href="index.php?pfad=showCategory&category=chemie">Chemie</a></li>
                <li><a href="index.php?pfad=showCategory&category=physik">Physik</a></li>
                <li><a href="index.php?pfad=showCategory&category=informatik">Informatik</a></li>
                <li><a href="index.php?pfad=showCategory&category=astronomie">Astronomie</a></li>
            </ul>
        </li>

        <li>
            <label class="nav__mobile-label">Gesellschaft & Werte</label>
            <ul class="nav__mobile-submenu">
                <li><a href="index.php?pfad=showCategory&category=geschichte">Geschichte</a></li>
                <li><a href="index.php?pfad=showCategory&category=erdkunde">Erdkunde</a></li>
                <li><a href="index.php?pfad=showCategory&category=sozialkunde">Sozialkunde</a></li>
                <li><a href="index.php?pfad=showCategory&category=wirtschaft">Wirtschaftskunde</a></li>
                <li><a href="index.php?pfad=showCategory&category=religion">Religion</a></li>
                <li><a href="index.php?pfad=showCategory&category=ethik">Ethikunterricht</a></li>
                <li><a href="index.php?pfad=showCategory&category=philosophie">Philosophie</a></li>
                <li><a href="index.php?pfad=showCategory&category=psychologie">Psychologie</a></li>
                <li><a href="index.php?pfad=showCategory&category=kunst">Kunst</a></li>
                <li><a href="index.php?pfad=showCategory&category=musik">Musik</a></li>
                <li><a href="index.php?pfad=showCategory&category=theater">Theater</a></li>
            </ul>
        </li>

        <li>
            <label class="nav__mobile-label">Technik & Praxis</label>
            <ul class="nav__mobile-submenu">
                <li><a href="index.php?pfad=showCategory&category=technik">Technik</a></li>
                <li><a href="index.php?pfad=showCategory&category=werken">Werken</a></li>
                <li><a href="index.php?pfad=showCategory&category=hauswirtschaft">Hauswirtschaft</a></li>
                <li><a href="index.php?pfad=showCategory&category=sport">Sport</a></li>
            </ul>
        </li>
    </ul>

    <!-- normale Navbar (Desktop) -->
    <div class="nav__center">
        <div class="nav__item nav__dropdown">
            <button class="nav__dropdown-toggle">Sprachen</button>
            <div class="nav__dropdown-menu">
                <a href="index.php?pfad=showCategory&category=deutsch">Deutsch</a>
                <a href="index.php?pfad=showCategory&category=englisch">Englisch</a>
                <a href="index.php?pfad=showCategory&category=franzoesisch">Französisch</a>
                <a href="index.php?pfad=showCategory&category=latein">Latein</a>
                <a href="index.php?pfad=showCategory&category=literatur">Literatur</a>
            </div>
        </div>

        <div class="nav__item nav__dropdown">
            <button class="nav__dropdown-toggle">MINT</button>
            <div class="nav__dropdown-menu">
                <a href="index.php?pfad=showCategory&category=mathe">Mathematik</a>
                <a href="index.php?pfad=showCategory&category=biologie">Biologie</a>
                <a href="index.php?pfad=showCategory&category=chemie">Chemie</a>
                <a href="index.php?pfad=showCategory&category=physik">Physik</a>
                <a href="index.php?pfad=showCategory&category=informatik">Informatik</a>
                <a href="index.php?pfad=showCategory&category=astronomie">Astronomie</a>
            </div>
        </div>

        <div class="nav__item nav__dropdown">
            <button class="nav__dropdown-toggle">Gesellschaft & Werte</button>
            <div class="nav__dropdown-menu">
                <a href="index.php?pfad=showCategory&category=geschichte">Geschichte</a>
                <a href="index.php?pfad=showCategory&category=erdkunde">Erdkunde</a>
                <a href="index.php?pfad=showCategory&category=sozialkunde">Sozialkunde</a>
                <a href="index.php?pfad=showCategory&category=wirtschaft">Wirtschaftskunde</a>
                <a href="index.php?pfad=showCategory&category=religion">Religion</a>
                <a href="index.php?pfad=showCategory&category=ethik">Ethikunterricht</a>
                <a href="index.php?pfad=showCategory&category=philosophie">Philosophie</a>
                <a href="index.php?pfad=showCategory&category=psychologie">Psychologie</a>
                <a href="index.php?pfad=showCategory&category=kunst">Kunst</a>
                <a href="index.php?pfad=showCategory&category=musik">Musik</a>
                <a href="index.php?pfad=showCategory&category=theater">Theater</a>
            </div>
        </div>

        <div class="nav__item nav__dropdown">
            <button class="nav__dropdown-toggle">Technik & Praxis</button>
            <div class="nav__dropdown-menu">
                <a href="index.php?pfad=showCategory&category=technik">Technik</a>
                <a href="index.php?pfad=showCategory&category=werken">Werken</a>
                <a href="index.php?pfad=showCategory&category=hauswirtschaft">Hauswirtschaft</a>
                <a href="index.php?pfad=showCategory&category=sport">Sport</a>
            </div>
        </div>
    </div>

    <div class="nav__right">

        <?php if (isset($_SESSION['user'])): ?>

            <a href="index.php?pfad=profile" class="nav__item nav__link">
                Profil
            </a>

            <div class="nav__search">
                <?php include_once 'search.php'; ?>
            </div>

            <a href="index.php?pfad=createArticle" class="nav__item nav__button">
                Beitrag erstellen
            </a>

            <form method="post" action="php/controller/logout-controller.php" class="nav__logout-form">
                <?php //csrf_field(); ?>
                <button type="submit" class="nav__item nav__button">
                    Abmelden
                </button>
            </form>

        <?php else: ?>

            <div class="nav__search">
                <?php include_once 'search.php'; ?>
            </div>

            <a href="index.php?pfad=login" class="nav__item nav__button">
                Anmelden
            </a>

            <a href="index.php?pfad=register" class="nav__item nav__button">
                Registrieren
            </a>

        <?php endif; ?>

    </div>
</nav>