@props([])

<div class="erp-sidebar-backdrop d-lg-none" id="erpSidebarBackdrop" aria-hidden="true"></div>

<aside class="erp-sidebar flex-column d-lg-none" id="erpSidebar" aria-label="{{ __('nav.sidebar_label') }}">
    <div class="erp-sidebar-inner py-2 flex-grow-1">
        @foreach ($navSidebarGroups as $group)
            @php
                $gkey = preg_replace('/[^a-z0-9_-]/i', '-', (string) ($group['key'] ?? 'grp'));
                $collapseId = 'nav-grp-'.$gkey;
                $expanded = $sidebar->groupHasActive($group);
                $lastSection = null;
            @endphp
            <div class="erp-sidebar-group border-bottom border-light mb-1 pb-1">
                <button class="erp-sidebar-group-toggle" type="button" data-bs-toggle="collapse"
                    data-bs-target="#{{ $collapseId }}" aria-expanded="{{ $expanded ? 'true' : 'false' }}"
                    aria-controls="{{ $collapseId }}">
                    <span class="d-flex align-items-center gap-2 min-w-0">
                        <i class="{{ $group['icon'] ?? 'fe fe-grid' }} flex-shrink-0"></i>
                        <span class="text-truncate">{{ $group['label'] }}</span>
                    </span>
                    <span class="erp-sidebar-chevron fe fe-chevron-down"></span>
                </button>
                <div id="{{ $collapseId }}" class="collapse {{ $expanded ? 'show' : '' }}">
                    @foreach ($group['items'] ?? [] as $item)
                        @php
                            $url = $sidebar->resolveUrl($item);
                            $section = $item['section'] ?? null;
                        @endphp
                        @continue($url === null)
                        @if ($section !== null && $section !== $lastSection)
                            @php $lastSection = $section; @endphp
                            <div class="erp-mega-subsection-title px-3 pt-2 pb-1">
                                {{ __('nav.mega.'.$section) }}
                            </div>
                        @endif
                        <a href="{{ $url }}"
                            class="erp-sidebar-link {{ $sidebar->isItemActive($item) ? 'is-active' : '' }}">
                            {{ $item['label'] }}
                        </a>
                    @endforeach
                </div>
            </div>
        @endforeach
    </div>
</aside>
