<?php
$path = str_replace('\\', '/', $_SERVER['SCRIPT_NAME'] ?? '');
$nav = [
    ['/dashboard.php', 'bi-speedometer2', 'Dashboard'],
];
if (can('quote:create')) $nav[] = ['/quotations/create.php', 'bi-file-earmark-plus', 'New Quotation'];
if (can('customer:view')) $nav[] = ['/customers/index.php', 'bi-people', 'Customers'];
if (can('product:view')) {
    $nav[] = ['/products/index.php', 'bi-box-seam', 'Products'];
    $nav[] = ['/price-list/index.php', 'bi-tags', 'Price List'];
}
if (can('quote:read') || can('quote:read_own')) {
    $nav[] = ['/quotations/view.php', 'bi-clock-history', current_user()['role'] === 'visitor' ? 'My Quotations' : 'Quotation History'];
}
if (can('report:view')) $nav[] = ['/reports/index.php', 'bi-bar-chart', 'Reports'];

if (current_user()['role'] === 'admin') {
    $nav[] = ['/settings/quotation-branding.php', 'bi-image', 'Quotation Branding'];
    $nav[] = ['/settings/index.php', 'bi-gear', 'Settings'];
    $nav[] = ['/backups/index.php', 'bi-database-down', 'Backups'];
    $nav[] = ['/users/index.php', 'bi-person-gear', 'User Management'];
    $nav[] = ['/activity-logs/index.php', 'bi-list-check', 'Activity Logs'];
}

$nav[] = ['/profile.php', 'bi-person-circle', 'Profile / Account'];
?>
<aside class="sidebar" id="appSidebar">
    <div class="sidebar-brand">
        <div class="d-flex align-items-center gap-2">
            <div class="logo-mark">F</div>
            <div class="brand-text"><strong>Fortunes</strong><span>Solar</span></div>
        </div>
        <button class="btn btn-sm btn-light sidebar-toggle d-none d-md-block" type="button" id="sidebarCollapseBtn">
            <i class="bi bi-chevron-left"></i>
        </button>
    </div>
    <nav>
        <?php foreach ($nav as [$href, $icon, $label]): $active = str_contains($path, dirname($href)) || str_ends_with($path, $href); ?>
            <a class="<?= $active ? 'active' : '' ?>" href="<?= APP_BASE . $href ?>" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="<?= e($label) ?>">
                <i class="bi <?= $icon ?>"></i><span class="nav-label"><?= e($label) ?></span>
            </a>
        <?php endforeach; ?>
    </nav>
</aside>
