<?php
    // NAV-01: grouped by module family (Fleet, Drivers, Customers) instead
    // of one flat "Menu" bucket — Route::has() below means a not-yet-built
    // route (e.g. Accounts, before CUST-01 lands) just stays invisible
    // rather than needing a second pass over this file later.
    $sections = [
        [
            'label' => 'Dispatch',
            'items' => [
                ['route' => 'admin.dashboard', 'icon' => 'bi-grid-1x2-fill', 'label' => 'Dashboard'],
                ['route' => 'admin.bookings.index', 'icon' => 'bi-taxi-front-fill', 'label' => 'Live Console', 'requires_company' => true],
                ['route' => 'admin.calls.index', 'icon' => 'bi-telephone-fill', 'label' => 'Call History', 'requires_company' => true],
            ],
        ],
        [
            'label' => 'Fleet',
            'items' => [
                ['route' => 'admin.vehicles.index', 'icon' => 'bi-car-front-fill', 'label' => 'Vehicle List', 'requires_company' => true],
                ['route' => 'admin.vehicle-types.index', 'icon' => 'bi-tag-fill', 'label' => 'Vehicle Type'],
                ['route' => 'admin.shifts.index', 'icon' => 'bi-clock-history', 'label' => 'Driver Shifts', 'requires_company' => true],
            ],
        ],
        [
            'label' => 'Drivers',
            'items' => [
                ['route' => 'admin.drivers.index', 'icon' => 'bi-person-badge-fill', 'label' => 'Driver List', 'requires_company' => true],
                ['route' => 'admin.payouts.index', 'icon' => 'bi-cash-coin', 'label' => 'Payouts'],
            ],
        ],
        [
            'label' => 'Customers',
            'items' => [
                ['route' => 'admin.customers.index', 'icon' => 'bi-people-fill', 'label' => 'Customer List', 'requires_company' => true],
                ['route' => 'admin.accounts.index', 'icon' => 'bi-briefcase-fill', 'label' => 'Accounts'],
            ],
        ],
        [
            'label' => 'Organization',
            'items' => [
                ['route' => 'admin.platform.index', 'icon' => 'bi-speedometer2', 'label' => 'Platform Overview', 'super_admin_only' => true],
                ['route' => 'admin.companies.index', 'icon' => 'bi-building-fill', 'label' => 'Companies', 'super_admin_only' => true],
                ['route' => 'admin.users.index', 'icon' => 'bi-person-lines-fill', 'label' => 'Staff Users'],
                ['route' => 'admin.roles.index', 'icon' => 'bi-shield-lock-fill', 'label' => 'Roles', 'super_admin_only' => true],
            ],
        ],
        [
            'label' => 'Growth',
            'items' => [
                ['route' => 'admin.demo-requests.index', 'icon' => 'bi-megaphone-fill', 'label' => 'Demo Leads', 'super_admin_only' => true],
                ['route' => 'admin.marketing-screenshots.index', 'icon' => 'bi-image-fill', 'label' => 'Marketing Site', 'super_admin_only' => true],
            ],
        ],
        [
            'label' => 'Insights',
            'items' => [
                ['route' => 'admin.reports.index', 'icon' => 'bi-bar-chart-fill', 'label' => 'Reports'],
            ],
        ],
        [
            'label' => 'System',
            'items' => [
                ['route' => 'admin.settings.edit', 'icon' => 'bi-gear-fill', 'label' => 'Settings', 'permission' => 'settings.manage', 'requires_company' => true],
                ['route' => 'admin.help.index', 'icon' => 'bi-life-preserver', 'label' => 'Help & Support'],
                ['route' => 'admin.support-tickets.index', 'icon' => 'bi-inbox-fill', 'label' => 'Support Tickets', 'super_admin_only' => true],
            ],
        ],
    ];
?>
<nav class="admin-sidebar">
    <div class="sidebar-brand">
        <span class="sidebar-brand-mark"><i class="bi bi-taxi-front-fill"></i></span>
        <span class="sidebar-brand-text"><?php echo e(config('app.name')); ?></span>
    </div>

    <div class="sidebar-nav-scroll">
        <?php $__currentLoopData = $sections; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $i => $section): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
            <?php
                $visibleItems = collect($section['items'])->filter(function ($item) {
                    if (! \Illuminate\Support\Facades\Route::has($item['route'])) {
                        return false;
                    }

                    if (($item['super_admin_only'] ?? false) && ! auth()->user()->isSuperAdmin()) {
                        return false;
                    }

                    // Settings is company-scoped (CompanySettingsController
                    // 404s without one) — a Super Admin has company_id=null,
                    // so hasPermission() below would otherwise still show
                    // this to them (it always returns true for a Super
                    // Admin) and land them on a dead link.
                    if (($item['requires_company'] ?? false) && auth()->user()->isSuperAdmin()) {
                        return false;
                    }

                    // RBAC-03: items like Settings are pure company-admin
                    // configuration with no useful read-only view for a
                    // Dispatcher, so the whole nav entry disappears rather
                    // than just the buttons on the page (unlike Drivers/
                    // Vehicles/Payouts, where the list itself stays useful).
                    if ($item['permission'] ?? null) {
                        return auth()->user()->hasPermission($item['permission']);
                    }

                    return true;
                });
            ?>
            <?php if($visibleItems->isEmpty()) continue; ?>
            <?php
                $sectionId = 'sidebarSection'.$i;
                $hasActiveItem = $visibleItems->contains(fn ($item) => request()->routeIs($item['route'].'*'));
            ?>
            <button type="button" class="sidebar-nav-toggle" data-bs-toggle="collapse" data-bs-target="#<?php echo e($sectionId); ?>"
                    aria-expanded="<?php echo e($hasActiveItem ? 'true' : 'false'); ?>" aria-controls="<?php echo e($sectionId); ?>">
                <span><?php echo e($section['label']); ?></span>
                <i class="bi bi-chevron-down sidebar-nav-chevron"></i>
            </button>
            <div class="collapse <?php echo e($hasActiveItem ? 'show' : ''); ?>" id="<?php echo e($sectionId); ?>">
                <ul class="nav">
                    <?php $__currentLoopData = $visibleItems; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $item): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li class="nav-item">
                            <a class="nav-link <?php echo e(request()->routeIs($item['route'].'*') ? 'active' : ''); ?>"
                               href="<?php echo e(route($item['route'])); ?>">
                                <i class="bi <?php echo e($item['icon']); ?> menu-icon"></i>
                                <span class="menu-title"><?php echo e($item['label']); ?></span>
                            </a>
                        </li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
            </div>
        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
    </div>

    <div class="sidebar-footer-card">
        <div class="sidebar-footer-avatar"><?php echo e(substr(auth()->user()->name ?? 'A', 0, 1)); ?></div>
        <div class="sidebar-footer-meta">
            <div class="sidebar-footer-name"><?php echo e(auth()->user()->name ?? 'Admin'); ?></div>
            <div class="sidebar-footer-role"><?php echo e(auth()->user()->role->label ?? 'Administrator'); ?></div>
        </div>
    </div>
</nav>
<?php /**PATH C:\xampp\htdocs\dispatch-v2\resources\views/components/admin/sidebar.blade.php ENDPATH**/ ?>