<?php
require_once 'session_helper.php';  
require_once 'cart.php';

safe_session_start();
$lg = isset($_SESSION['user_id']);
$adm = $lg && isset($_SESSION['user_role']) && $_SESSION['user_role'] === 'admin';
$uname = $lg ? $_SESSION['user_name'] : '';

$cart_cnt = getCartCount();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Allura Dry Clean</title>
    <link rel="icon" type="image/png" href="/allura/img/logo.png">
    <link rel="stylesheet" href="/allura/css/style.css">
    <link rel="stylesheet" href="/allura/css/notifications.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css">
    <script src="/allura/js/notifications.js"></script>
    <script src="/allura/js/cart.js"></script>
    <?php if ($lg): ?>
    <script src="/allura/js/user-notifications.js"></script>
    <?php endif; ?>
</head>
<body>
    <header>
        <!-- الشعار -->
        <div class="logo">
            <img src="/allura/img/logo.png" alt="Allura Logo">
        </div>
        
        <!-- الروابط -->
        <nav>
            <ul>
                <li><a href="/allura/home.php"><i class="fas fa-home"></i> Home</a></li>
                <li><a href="/allura/service.php"><i class="fas fa-soap"></i> Service</a></li>
                <li><a href="/allura/contact.php"><i class="fa-solid fa-envelope"></i> Contact</a></li>
                <li>
                    <a href="/allura/cart.php">
                        <i class="fas fa-shopping-cart"></i> Cart
                        <span class="cart-count" style="<?php echo $cart_cnt > 0 ? 'display: inline;' : 'display: none;'; ?>"><?php echo $cart_cnt; ?></span>
                    </a>
                </li>
                <?php if ($lg): ?>
                <li class="notification-bell">
                    <i class="fas fa-bell" id="notificationBell"></i>
                    <span class="notification-count" id="notificationCount" style="display: none;">0</span>
                    <div class="notification-dropdown" id="notificationDropdown">
                        <div class="notification-header">Notifications</div>
                        <div class="notification-list" id="notificationList">
                            <div class="no-notifications">No new notifications</div>
                        </div>
                    </div>
                </li>
                <?php endif; ?>
                
                <?php if ($adm): ?>
                    <li><a href="/allura/admin/admin.php"><i class="fas fa-cog"></i> Admin Panel</a></li>
                <?php endif; ?>
            </ul>
        </nav>

        <div class="login">
            <?php if ($lg): ?>
                <div class="user-dropdown">
                    <span class="welcome-text">Welcome, <?php echo htmlspecialchars($uname); ?>! ▼</span>
                    <div class="dropdown-content">
                        <a href="/allura/php/profile.php">Profile</a>
                        <a href="/allura/php/logout.php">Logout</a>
                    </div>
                </div>
            <?php else: ?>
                <a href="/allura/login.php">Login</a>
            <?php endif; ?>
        </div>
    </header>
</body>
</html>