<?php
$user_role = strtolower($_SESSION['role'] ?? 'guest');

// helper function
function canAccess($roles){
    global $user_role;
    $roles = array_map('strtolower', (array)$roles);
    return $user_role === 'admin' || in_array($user_role, $roles);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>

    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>

    <style>
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f5f5f5;
        }
        .navbar-brand { font-weight: bold; }
        .dropdown-menu .dropdown-item:hover {
            background-color: #e9f7ef;
            font-weight: bold;
        }
        .btn-custom {
            border-radius: 0.35rem;
            font-weight: bold;
        }
    </style>
</head>

<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark px-3">
    <a class="navbar-brand" href="sales_pos.php">
     
    </a>

    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
        <span class="navbar-toggler-icon"></span>
    </button>

    <div class="collapse navbar-collapse" id="navbarNav">
        <ul class="navbar-nav ms-auto">

            <!-- ================= POS (FIXED) ================= -->
            <?php if($user_role === 'admin' || in_array($user_role, ['bartender','waiter'])): ?>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown">
                    <i class="fa fa-cash-register"></i> <b>POS</b>
                </a>

                <ul class="dropdown-menu dropdown-menu-end shadow">

                    <?php if(canAccess(['bartender'])): ?>
                    <li>
                        <a class="dropdown-item" href="sales_pos.php">
                            <i class="fa fa-cash-register text-success"></i> Bar POS
                        </a>
                    </li>
                    <?php endif; ?>

                    <?php if(canAccess(['waiter'])): ?>
                    <li>
                        <a class="dropdown-item" href="restaurant_pos.php">
                            <i class="fa fa-utensils text-danger"></i> Restaurant POS
                        </a>
                    </li>
                    <?php endif; ?>

                </ul>
            </li>
            <?php endif; ?>

            <!-- Restaurant -->
            <?php if(canAccess(['waiter'])): ?>
            <li class="nav-item">
                <a href="restaurant.php" class="nav-link">
                    <i class="fa fa-boxes-stacked"></i> Restaurant Dashboard
                </a>
            </li>
            <?php endif; ?>

            <!-- Bar -->
            <?php if(canAccess(['bartender'])): ?>
            <li class="nav-item">
                <a href="bar.php" class="nav-link">
                    <i class="fa fa-boxes-stacked"></i> Bar
                </a>
            </li>
            <?php endif; ?>

            <!-- Kitchen -->
            <?php if(canAccess(['chef'])): ?>
            <li class="nav-item">
                <a href="kitchen_dashboard.php" class="nav-link">
                    <i class="fa fa-boxes-stacked"></i> Kitchen
                </a>
            </li>
            <?php endif; ?>

            <!-- Accounts -->
            <?php if(canAccess(['accountant'])): ?>
            <li class="nav-item">
                <a href="accounts.php" class="nav-link">
                    <i class="fa fa-boxes-stacked"></i> Accounts
                </a>
            </li>
            <?php endif; ?>

            <!-- Manager -->
            <?php if(canAccess(['manager'])): ?>
            <li class="nav-item">
                <a href="manager.php" class="nav-link">
                    <i class="fa fa-boxes-stacked"></i> Manager
                </a>
            </li>
            <?php endif; ?>

            <!-- Front Office -->
            <?php if(canAccess(['front_office'])): ?>
            <li class="nav-item">
                <a href="front_office_dashboard.php" class="nav-link">
                    <i class="fa fa-boxes-stacked"></i> Front Office
                </a>
            </li>
            <?php endif; ?>

            <!-- Inventory -->
            <?php if(canAccess(['stores'])): ?>
            <li class="nav-item">
                <a href="inventory.php" class="nav-link">
                    <i class="fa fa-boxes-stacked"></i> Inventory
                </a>
            </li>
            <?php endif; ?>

            <!-- Housekeeping -->
            <?php if(canAccess(['housekeeping'])): ?>
            <li class="nav-item">
                <a href="house_keeping.php" class="nav-link">
                    <i class="fa fa-boxes-stacked"></i> HouseKeeping
                </a>
            </li>
            <?php endif; ?>

            <!-- Profile -->
            <?php if($user_role !== 'guest'): ?>
            <li class="nav-item">
                <a class="nav-link" href="change_pass.php">
                    <i class="fa fa-user-cog"></i> Profile
                </a>
            </li>
            <?php endif; ?>

            <!-- Settings (ADMIN ONLY) -->
            <?php if($user_role === 'admin'): ?>
            <li class="nav-item">
                <a class="nav-link" href="settings.php">
                    <i class="fa fa-cogs"></i> 
                </a>
            </li>
            <?php endif; ?>

            <li class="nav-item">
                <a href="logout.php" class="btn btn-secondary btn-custom ms-2">
                    <i class="fa fa-sign-out-alt"></i> Logout
                </a>
            </li>

        </ul>
    </div>
</nav>

<div class="container-fluid mt-4">
