<?php
$settingsPath = parse_url($_SERVER['REQUEST_URI'] ?? '/settings/general', PHP_URL_PATH);
$settingsSection = match(true) {
    str_starts_with($settingsPath, '/settings/users') => 'users',
    str_starts_with($settingsPath, '/settings/permissions') => 'permissions',
    str_starts_with($settingsPath, '/settings/privacy') => 'privacy',
    str_starts_with($settingsPath, '/settings/species') => 'species',
    str_starts_with($settingsPath, '/settings/rooms') => 'rooms',
    str_starts_with($settingsPath, '/settings/pricing') => 'pricing',
    str_starts_with($settingsPath, '/settings/inventory') => 'inventory',
    str_starts_with($settingsPath, '/settings/lab-references') => 'lab-references',
    str_starts_with($settingsPath, '/settings/public-site') => 'public-site',
    str_starts_with($settingsPath, '/settings/backups') => 'backups',
    str_starts_with($settingsPath, '/settings/health') => 'health',
    str_starts_with($settingsPath, '/settings/notifications') => 'notifications',
    str_starts_with($settingsPath, '/settings/audit') => 'audit',
    str_starts_with($settingsPath, '/settings/asm3') => 'asm3',
    str_starts_with($settingsPath, '/settings/data') => 'data',
    default => 'general',
};
require_once __DIR__ . '/_settings_links.php';
$settingsLinks = settingsNavigationLinks();
?>
<nav aria-label="<?= h(t('settings.navigation')) ?>" class="card card-sm mb-3 settings-section-nav">
    <div class="card-body py-3 d-flex flex-wrap align-items-stretch gap-3">
        <?php foreach (['general','business','access','maintenance'] as $group): ?><div class="settings-nav-group">
            <div class="subheader mb-2"><?= h(settingsGroupLabel($group)) ?></div>
            <div class="d-flex flex-wrap gap-2"><?php foreach ($settingsLinks as $key => [$href,$icon,$label,$linkGroup]): if ($linkGroup !== $group) {
                continue;
            } ?><a class="btn btn-sm <?= $settingsSection === $key ? 'btn-dark' : 'btn-outline-secondary' ?>"
                    href="<?= h($href) ?>" <?= $settingsSection === $key ? 'aria-current="page"' : '' ?>><?= $icon ?>
                    <?= h($label) ?></a><?php endforeach; ?></div>
        </div><?php endforeach; ?>
    </div>
</nav>
