<?php
    defined('nav') or header('Location: ./../');
    define('add-order', TRUE);
    include 'inc/add-order-modal.php';

    $username = $_SESSION['username'];
    $query = "SELECT admin FROM user WHERE username = '$username'";
    $result = mysqli_query($dbc, $query);
    while($row = mysqli_fetch_array($result)) {
        $admin = $row['admin'];
        $_SESSION['dir'] = $admin;
    }
?>
<section class="nav">
    <div class="wrapper">
        <div class="nav-menu">
            <div class="nav-menu_left">
                <?php if($admin == 1) { ?>
                    <a class="add-order-btn" onclick="openAddOrder()"><i data-feather="plus-square"></i></a>
                <?php } ?>
            </div>
            <div class="nav-menu_center">
                <?php 
                    if($admin == 1) {
                ?>
                    <a href="./" <?php if (basename($_SERVER['PHP_SELF']) == 'index.php'){echo 'class="active"';} ?>>Menu</a>
                    <a href="narudzbe" <?php if (basename($_SERVER['PHP_SELF']) == 'narudzbe.php'){echo 'class="active"';} ?>>Narudžbe</a>
                    <a href="statistika" <?php if (basename($_SERVER['PHP_SELF']) == 'statistika.php'){echo 'class="active"';} ?>>Statistika</a>
                    <a href="korisnici" <?php if (basename($_SERVER['PHP_SELF']) == 'korisnici.php' || basename($_SERVER['PHP_SELF']) == 'registracija.php'){echo 'class="active"';} ?>>Korisnici</a>
                <?php } else { ?>
                    <a href="./" <?php if (basename($_SERVER['PHP_SELF']) == 'index.php'){echo 'class="active"';} ?>>Menu</a>
                <?php } ?>
            </div>
            <div class="nav-menu_right">
                <button class="dropbtn"><img src="https://ui-avatars.com/api/?name=<?php echo $_SESSION['name']; ?>&rounded=true&length=1&background=E6E6E6&bold=true" /><?php echo $_SESSION['name']; ?></button>
                <div class="dropdown-content">
                    <a href="./povijest"><i data-feather="list"></i>Tvoje narudžbe</a>
                    <a href="./promjena-lozinke"><i data-feather="key"></i>Promjena lozinke</a>
                    <button onclick="logout()"><i data-feather="log-out"></i>Odjava</button>
                </div>
            </div>
            <!-- MOBILNA NAVIGACIJA -->
            <div class="nav-mobile">
                <button class="dropbtn-mobile"><img src="https://ui-avatars.com/api/?name=<?php echo $_SESSION['name']; ?>&rounded=true&length=1&background=E6E6E6&bold=true" /><?php echo $_SESSION['name']; ?></button>
                <div class="dropdown-content-mobile">
                    <a href="./"><i data-feather="home"></i>Menu</a>
                    <?php if($admin == 1) { ?>
                        <a href="narudzbe"><i data-feather="shopping-cart"></i>Narudžbe</a>
                    <?php } ?>
                    <a href="./povijest"><i data-feather="list"></i>Tvoje narudžbe</a>
                    <button onclick="logout()"><i data-feather="log-out"></i>Odjava</button>
                </div>
            </div>
        </div>
    </div>
</section>