<?php
/**
 * Standard platform user dropdown (notifications' sibling in the top navbar).
 * Required in scope: $baseUrl, $user. Include after notification-bell + theme-toggle.
 * Kept as one partial so every console page shows an identical account menu.
 */
?>
<style>
    /* Instant, left-opening tooltips for the account dropdown items. */
    .acct-menu .dropdown-item { position: relative; }
    .acct-menu .dropdown-item[data-tip]:hover::after {
        content: attr(data-tip);
        position: absolute; right: calc(100% + 12px); top: 50%; transform: translateY(-50%);
        background: var(--pp-navbar-bg, #0f172a); color: #f4f6fb;
        font-size: .72rem; font-weight: 600; line-height: 1.35; text-align: left;
        white-space: normal; width: max-content; max-width: 230px;
        padding: 6px 10px; border-radius: 8px; z-index: 6000; pointer-events: none;
        box-shadow: 0 10px 26px rgba(0, 0, 0, .4); border: 1px solid rgba(255, 255, 255, .14);
    }
    @media (max-width: 575.98px) { .acct-menu .dropdown-item[data-tip]:hover::after { display: none; } }
</style>
<div class="dropdown">
    <a href="#" class="d-flex align-items-center text-white text-decoration-none dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false">
        <i class="bi bi-person-circle me-1 me-md-2"></i><span class="nav-username d-none d-sm-inline"><?= htmlspecialchars($user['username'] ?? 'Admin') ?></span>
    </a>
    <ul class="dropdown-menu dropdown-menu-dark dropdown-menu-end acct-menu">
        <?php if (\PpPhp\Core\Security::IsOwner()): /* platform owner only */ ?>
            <?php $__vendorOnly = !class_exists(\PpPhp\Core\Licensing\LicenseGate::class) || !\PpPhp\Core\Licensing\LicenseGate::isClientEdition(); ?>
            <?php if ($__vendorOnly): ?><li><a class="dropdown-item" href="<?= $baseUrl ?>/platform/app-bundle" data-tip="Package this platform into a clean, secret-free ZIP for a fresh server install"><i class="bi bi-box-seam me-2"></i>App Bundle</a></li><?php endif; ?>
            <li><a class="dropdown-item" href="<?= $baseUrl ?>/platform/visitors" data-tip="Who has been visiting this installation — countries, pages and devices"><i class="bi bi-people me-2"></i>Visitors</a></li>
            <?php if ($__vendorOnly): ?>
            <li><hr class="dropdown-divider"></li>
            <li><h6 class="dropdown-header"><i class="bi bi-send me-1"></i>Deliverables</h6></li>
            <li><a class="dropdown-item" href="<?= $baseUrl ?>/platform/deliverables/marketing" data-tip="Download the public ppradhan.com marketing website to deploy at your domain root"><i class="bi bi-globe2 me-2"></i>Marketing Website</a></li>
            <li><a class="dropdown-item" href="<?= $baseUrl ?>/platform/deliverables/community" data-tip="Rebuild &amp; download the community forum as a standalone installer (install.php)"><i class="bi bi-box-seam me-2"></i>Community Installer</a></li>
            <?php endif; ?>
            <li><hr class="dropdown-divider"></li>
        <?php endif; ?>
        <?php if (\PpPhp\Core\Security::IsAdmin()): /* superadmin + owner */ ?>
            <li><a class="dropdown-item" href="<?= $baseUrl ?>/users" data-tip="Add, edit and remove user accounts; review trial requests"><i class="bi bi-people me-2"></i>Manage Users</a></li>
            <?php
            $ppShowEstablish = !\PpPhp\Core\Auth\OwnerVerification::isVerified();
            if ($ppShowEstablish && class_exists(\PpPhp\Core\Licensing\LicenseGate::class) && \PpPhp\Core\Licensing\LicenseGate::isClientEdition()) {
                $ppShowEstablish = \PpPhp\Core\Security::IsOwner() || \PpPhp\Core\Auth\OwnerVerification::challengePending();
            }
            ?>
            <?php if ($ppShowEstablish): ?>
            <li><a class="dropdown-item text-warning" href="<?= $baseUrl ?>/platform/owner-setup" data-tip="Establish the platform owner via an email code sent to the owner mailbox"><i class="bi bi-patch-check me-2"></i>Establish Owner</a></li>
            <?php endif; ?>
            <li><a class="dropdown-item" href="<?= $baseUrl ?>/platform/updates" data-tip="Check for and apply platform updates to this installation">
                <i class="bi bi-arrow-repeat me-2"></i>Updates
                <span class="badge bg-secondary ms-1" style="font-size:.65rem">v<?= htmlspecialchars(\PpPhp\Core\PlatformSettings::version()) ?></span>
            </a></li>
            <?php include constant('BASE_PATH') . '/core/views/license-menu.php'; ?>
            <li><hr class="dropdown-divider"></li>
        <?php endif; ?>
        <li><a class="dropdown-item" href="<?= $baseUrl ?>/profile" data-tip="View and edit your own account details"><i class="bi bi-person me-2"></i>Profile</a></li>
        <li><a class="dropdown-item" href="<?= $baseUrl ?>/account/security" data-tip="Password, two-factor authentication and sessions"><i class="bi bi-shield-lock me-2"></i>Security &amp; 2FA</a></li>
        <li><hr class="dropdown-divider"></li>
        <li><a class="dropdown-item" href="<?= $baseUrl ?>/logout" onclick="window.location.href=this.href; return false;" data-tip="Sign out of your account"><i class="bi bi-box-arrow-right me-2"></i>Sign out</a></li>
    </ul>
</div>
