<header>
    <nav class="navbar navbar-expand-md navbar-dark bg-primary shadow-sm align-middle">
        <div class="container px-3">
            <a class="navbar-brand" href="<?= site_url() ?>">
                <i class="bi bi-box px-2"></i><?= BASE_NAME ?>
            </a>

            <button class="navbar-toggler" type="button" data-bs-toggle="collapse"
                    data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
                    aria-expanded="false" aria-label="Toggle navigation">
                <span class="navbar-toggler-icon"></span>
            </button>

            <div class="collapse navbar-collapse" id="navbarSupportedContent">

                <?php if (session()->has('userid')) : ?>

                    <!-- MENU TRÁI -->
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0">
                        <li class="nav-item">
                            <a class="nav-link text-white" href="<?= site_url('keys') ?>">Danh Sách Key</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-white" href="<?= site_url('keys/generate') ?>">Tạo Key</a>
                        </li>
                    </ul>

                    <!-- MENU PHẢI -->
                    <ul class="navbar-nav ms-auto mb-2 mb-lg-0">
                        <li class="nav-item dropdown">

                            <a class="nav-link dropdown-toggle text-white" href="#" id="navbarDropdown"
                               role="button" data-bs-toggle="dropdown" aria-expanded="false">
                                <i class="bi bi-person-circle pe-2"></i><?= getName($user) ?>
                            </a>

                            <ul class="dropdown-menu dropdown-menu-end dropdown-menu-lg-start" aria-labelledby="navbarDropdown">


                                <!-- 🎩 ADMIN -->
                                <?php if ($user->level == 1) : ?>

                                    <li class="dropdown-item text-muted">Admin</li>
                                    <li><hr class="dropdown-divider"></li>

                                    <li>
                                        <a class="dropdown-item" href="<?= site_url('admin/manage-users') ?>">
                                            <i class="bi bi-person-check"></i> Quản Lý Reseller
                                        </a>
                                    </li>
                                    
                                    <li>
                                        <a class="dropdown-item" href="<?= site_url('Game/game.php') ?>">
                                            <i class="bi bi-person-check"></i> Quản Lý Game
                                        </a>
                                    </li>

                                    <li>
                                        <a class="dropdown-item" href="<?= site_url('Server') ?>">
                                            <i class="bi bi-hdd-network"></i> Hệ thống online
                                        </a>
                                    </li>

                                    <li>
                                        <a class="dropdown-item" href="<?= site_url('settings') ?>">
                                            <i class="bi bi-gear"></i> Settings
                                        </a>
                                    </li>

                                    <li>
                                        <a class="dropdown-item" href="<?= site_url('admin/create-referral') ?>">
                                            <i class="bi bi-person-plus"></i> Tạo Reseller
                                        </a>
                                    </li>

                                    <li><hr class="dropdown-divider"></li>


                                <!-- 🛒 RESELLER -->
                                <?php elseif ($user->level == 2) : ?>

                                    <li class="dropdown-item text-muted">Reseller</li>
                                    <li><hr class="dropdown-divider"></li>

                                    <li>
                                        <a class="dropdown-item" href="<?= site_url('settings') ?>">
                                            <i class="bi bi-gear"></i> Settings
                                        </a>
                                    </li>

                                    <li><hr class="dropdown-divider"></li>

                                <?php endif; ?>


                                <!-- 🚪 LOGOUT -->
                                <li>
                                    <a class="dropdown-item text-danger" href="<?= site_url('logout') ?>">
                                        <i class="bi bi-box-arrow-in-left"></i> ĐĂNG XUẤT
                                    </a>
                                </li>

                            </ul>

                        </li>
                    </ul>

                <?php endif; ?>

            </div>
        </div>
    </nav>
</header>