@props([
    'megaSidebar',
    'badges',
    'groupKey',
    'items',
    'hrSections' => [],
])

@php $adminHeaderShown = false; @endphp
@if ($groupKey === 'hr' && $hrSections !== [])
    <div class="erp-mega-browse-grid" role="navigation" aria-label="{{ __('nav.group.hr') }}">
        @foreach ($hrSections as $section)
            <section class="erp-mega-browse-card {{ $section['key'] === 'recruitment' ? 'erp-mega-browse-card--wide' : '' }}"
                data-hr-section="{{ $section['key'] }}">
                <div class="erp-mega-browse-card__title">
                    <i class="{{ $section['icon'] ?? 'fe fe-grid' }}" aria-hidden="true"></i>
                    <span>{{ $section['label'] }}</span>
                </div>
                <div class="erp-mega-browse-card__divider" aria-hidden="true"></div>
                <nav class="erp-mega-browse-card__links">
                    @foreach ($section['items'] as $item)
                        @php $url = $megaSidebar->resolveUrl($item); @endphp
                        @continue($url === null)
                        <a href="{{ $url }}"
                            class="mega-nav-link mega-nav-link--dense {{ $megaSidebar->isItemActive($item) ? 'is-active' : '' }}">
                            <span class="text-truncate">{{ $item['label'] }}</span>
                            @if (isset($badges[(string) ($item['route'] ?? '')]))
                                <span class="badge bg-warning text-dark">{{ $badges[(string) $item['route']] }}</span>
                            @endif
                        </a>
                    @endforeach
                </nav>
            </section>
        @endforeach
    </div>
@else
    <div class="erp-mega-section-title">{{ __('nav.mega.browse') }}</div>
    <div class="d-flex flex-column gap-1">
        @foreach ($items as $item)
            @php
                $url = $megaSidebar->resolveUrl($item);
                $rn = (string) ($item['route'] ?? '');
            @endphp
            @continue($url === null)
            @if (str_starts_with($rn, 'admin.') && ! $adminHeaderShown)
                @php $adminHeaderShown = true; @endphp
                <div class="dropdown-divider my-2"></div>
                <div class="erp-mega-section-title mb-1">{{ __('nav.mega.platform_admin') }}</div>
            @endif
            <a href="{{ $url }}" class="mega-nav-link {{ $megaSidebar->isItemActive($item) ? 'is-active' : '' }}">
                <span>{{ $item['label'] }}</span>
                @if (isset($badges[$rn]))
                    <span class="badge bg-warning text-dark ms-1">{{ $badges[$rn] }}</span>
                @endif
            </a>
        @endforeach
    </div>
@endif
