<?php


if(isset($_POST['logout'])) {
    // Clear all session data
    session_unset();
    session_destroy();

    // Redirect to login page
    header("Location: login");
    exit(); // always call exit after header redirect
}
?>


<nav class="navbar navbar-expand bg-secondary navbar-dark sticky-top px-4 py-0">
    <a href="index.html" class="navbar-brand d-flex d-lg-none me-4">
        <img src="img/logo.png" alt="ai_dine logo" style="height: 50px; width: auto;">
    </a>

    <a href="#" class="sidebar-toggler flex-shrink-0">
        <i class="fa fa-bars"></i>
    </a>
    <form class="d-none d-md-flex ms-4">
        <input class="form-control bg-dark border-0" type="search" placeholder="Search">
    </form>
    <div class="navbar-nav align-items-center ms-auto">
        
        <div class="nav-item dropdown">
            <a href="#" class="nav-link dropdown-toggle" data-bs-toggle="dropdown">
                <img class="rounded-circle me-lg-2" src="img/user.png" alt="" style="width: 40px; height: 40px;">
                <span class="d-none d-lg-inline-flex"><?php echo $_SESSION["name"]?></span>
            </a>
            <div class="dropdown-menu dropdown-menu-end bg-secondary border-0 rounded-0 rounded-bottom m-0">
                <a href="#" class="dropdown-item">My Profile</a>
                <a href="#" class="dropdown-item">Settings</a>
                <form action="" method="post">
                    <a href="#" class="dropdown-item">
                        <input type="hidden"  name="logout">
                        <button class="btn" type="submit">Logout</button>
                    </a>

                </form>
            </div>
        </div>
    </div>
</nav>