<?php
if (defined('HEADER_RENDERED')) return;
define('HEADER_RENDERED', true);
$curr = basename($_SERVER['PHP_SELF'] ?? '');
?>
<nav class="navbar navbar-expand-lg navbar-pro">
    <div class="container-fluid px-4">
        <a class="navbar-brand" href="dashboard.php">
            <i class="bi bi-gear-fill me-2"></i>
            <span>نظام صيانة الأجهزة</span>
        </a>
        <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-label="القائمة">
            <span class="navbar-toggler-icon"></span>
        </button>
        <div class="collapse navbar-collapse" id="navbarNav">
            <ul class="navbar-nav me-auto gap-1">
                <li class="nav-item"><a class="nav-link <?= $curr === 'dashboard.php' ? 'active' : '' ?>" href="dashboard.php"><i class="bi bi-house-door"></i> الرئيسية</a></li>
                <li class="nav-item"><a class="nav-link <?= $curr === 'search.php' ? 'active' : '' ?>" href="search.php"><i class="bi bi-search"></i> بحث</a></li>
                <li class="nav-item"><a class="nav-link <?= $curr === 'hospitals.php' ? 'active' : '' ?>" href="hospitals.php"><i class="bi bi-hospital"></i> المستشفيات</a></li>
                <li class="nav-item"><a class="nav-link <?= $curr === 'devices.php' ? 'active' : '' ?>" href="devices.php"><i class="bi bi-plus-circle"></i> إضافة جهاز</a></li>
                <li class="nav-item"><a class="nav-link <?= in_array($curr, ['devices_list.php','device_view.php']) ? 'active' : '' ?>" href="devices_list.php"><i class="bi bi-cpu"></i> قائمة الأجهزة</a></li>
                <li class="nav-item"><a class="nav-link <?= $curr === 'customers.php' ? 'active' : '' ?>" href="customers.php"><i class="bi bi-people"></i> الزبائن</a></li>
                <li class="nav-item"><a class="nav-link <?= $curr === 'maintenance_query.php' ? 'active' : '' ?>" href="maintenance_query.php"><i class="bi bi-tools"></i> صيانة دورية</a></li>
                <li class="nav-item"><a class="nav-link <?= $curr === 'warranty.php' ? 'active' : '' ?>" href="warranty.php"><i class="bi bi-shield-check"></i> الضمان</a></li>
                <li class="nav-item dropdown">
                    <a class="nav-link dropdown-toggle" href="#" data-bs-toggle="dropdown"><i class="bi bi-gear"></i> الإعدادات</a>
                    <ul class="dropdown-menu dropdown-menu-end">
                        <li><a class="dropdown-item" href="engineers.php"><i class="bi bi-person-badge me-2"></i>المهندسين</a></li>
                        <li><a class="dropdown-item" href="companies.php"><i class="bi bi-building me-2"></i>الشركات</a></li>
                        <li><a class="dropdown-item" href="device_models.php"><i class="bi bi-collection me-2"></i>أسماء الأجهزة وموديلاتها</a></li>
                        <?php if (!empty($_SESSION['is_admin'])): ?>
                        <li><hr class="dropdown-divider"></li>
                        <li><a class="dropdown-item" href="users.php"><i class="bi bi-people me-2"></i>المستخدمين والصلاحيات</a></li>
                        <li><a class="dropdown-item" href="activity_log.php"><i class="bi bi-journal-text me-2"></i>سجل النشاطات</a></li>
                        <?php endif; ?>
                    </ul>
                </li>
            </ul>
            <div class="dropdown navbar-user-dropdown">
                <a class="navbar-user-btn dropdown-toggle" href="#" data-bs-toggle="dropdown">
                    <i class="bi bi-person-circle"></i>
                    <span class="navbar-user-name"><?= htmlspecialchars($_SESSION['username'] ?? '') ?></span>
                </a>
                <ul class="dropdown-menu dropdown-menu-start dropdown-menu-pro" data-bs-boundary="viewport">
                    <li class="dropdown-header">
                        <div class="fw-600"><?= htmlspecialchars($_SESSION['username'] ?? '') ?></div>
                        <small class="text-muted">مرحباً بك</small>
                    </li>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item" href="change_password.php"><i class="bi bi-key me-2"></i>تغيير كلمة المرور</a></li>
                    <?php if (!empty($_SESSION['is_admin'])): ?>
                    <li><a class="dropdown-item" href="users.php"><i class="bi bi-people me-2"></i>المستخدمين والصلاحيات</a></li>
                    <li><a class="dropdown-item" href="activity_log.php"><i class="bi bi-journal-text me-2"></i>سجل النشاطات</a></li>
                    <?php endif; ?>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item text-danger" href="?logout=1"><i class="bi bi-box-arrow-right me-2"></i>تسجيل الخروج</a></li>
                </ul>
            </div>
        </div>
    </div>
</nav>
