<?php
    $context = System\Classes\SettingsManager::instance()->getContext();

    $collapsedSections = explode('|',
        isset($_COOKIE['sidenav_treegroupStatus']) ? $_COOKIE['sidenav_treegroupStatus'] : null
    );
?>

<ul class="top-level">
    <?php foreach ($items as $section => $pages):
        $collapsed = in_array($section, $collapsedSections);
    ?>
        <li data-group-code="<?= e($section) ?>" <?= $collapsed ? 'data-status="collapsed"' : null ?>>
            <div class="group">
                <h3><?= e($section) ?></h3>
            </div>

            <ul <?= $collapsed ? 'style="overflow: visible; height: 0px; display: none;"' : null ?>>
            <?php foreach ($pages as $id => $page): ?>
                <li
                    <?php if ($active === $id): ?>class="active"<?php endif ?>
                    data-keywords=""
                >
                    <a href="<?= $page['url'] ?>">
                        <span class="nav-label">
                            <?= e($page['label']) ?>
                        </span>
                    </a>
                </li>
            <?php endforeach ?>
            </ul>
        </li>
    <?php endforeach ?>
</ul>
