<?php
/**
 * Shared project sidebar nav-item list. Included inside a <ul> by each module's
 * shell.php (desktop and mobile). On a STANDALONE project (no database) the
 * DB-only modules render as locked (non-navigable + lock glyph + tooltip).
 *
 * Expects: $navItems, $project, $baseUrl. Optional: $navMobile (bool).
 */
$__standalone = \PpPhp\Core\ProjectDatabaseProfile::isStandaloneSlug((string)($project['slug'] ?? ''));
$__mobile = !empty($navMobile);
// Print the locked-item style once per request.
if ($__standalone && empty($GLOBALS['__ppNavLockCss'])):
    $GLOBALS['__ppNavLockCss'] = true; ?>
    <style>
        .project-nav-locked { display: flex; align-items: center; cursor: not-allowed; opacity: .55; }
        .project-nav-locked .bi-lock-fill { margin-left: auto; }
        .sidebar .project-nav-locked:hover, .offcanvas .project-nav-locked:hover { background: transparent; }
    </style>
<?php endif; ?>
<?php
foreach ($navItems as $item):
    $locked = $__standalone && in_array($item['uri'] ?? '', \PpPhp\Core\ProjectNav::DB_ONLY, true);
    $icon = htmlspecialchars($item['icon'] ?? 'circle');
    $label = htmlspecialchars((string)($item['label'] ?? ''));
    ?>
    <li class="nav-item">
        <?php if ($locked): ?>
            <span class="nav-link disabled project-nav-locked<?= $__mobile ? ' text-white' : '' ?>"
                  data-nav="<?= htmlspecialchars($item['uri'] ?? '') ?>"
                  title="Needs a database — this is a standalone app"
                  data-ppd-tip="This module needs a database. This is a standalone (database-free) app — design its pages in the Designer.">
                <i class="bi bi-<?= $icon ?> me-2 pp-nav-ico"></i><?= $label ?><i class="bi bi-lock-fill ms-auto opacity-75" style="font-size:.8em"></i>
            </span>
        <?php else: ?>
            <a href="<?= $baseUrl ?>/project/<?= urlencode((string)($project['slug'] ?? '')) ?><?= htmlspecialchars($item['uri'] ?? '#') ?>"
               class="nav-link <?= $__mobile ? 'text-white ' : '' ?><?= ($item['active'] ?? false) ? 'active' : '' ?>"
               data-nav="<?= htmlspecialchars($item['uri'] ?? '') ?>">
                <i class="bi bi-<?= $icon ?> me-2 pp-nav-ico"></i><?= $label ?>
            </a>
        <?php endif; ?>
    </li>
<?php endforeach; ?>
