@php
    $isManager = auth()->user()->hasAnyRole(['Admin', 'Gestor']);
    $items = [
        [
            'label' => 'Visão geral',
            'route' => 'settings.index',
            'match' => ['settings.index'],
            'roles' => true,
        ],
        [
            'label' => 'Minha conta',
            'route' => 'settings.account',
            'match' => ['settings.account'],
            'roles' => true,
        ],
        [
            'label' => 'Organização',
            'route' => 'settings.organization',
            'match' => ['settings.organization'],
            'roles' => $isManager,
        ],
        [
            'label' => 'Equipe',
            'route' => 'organizations.members',
            'match' => ['organizations.members', 'organizations.members.*', 'organizations.invitations.*'],
            'roles' => $isManager,
        ],
        [
            'label' => 'Plano',
            'route' => 'settings.plan',
            'match' => ['settings.plan', 'billing.plan', 'billing.checkout', 'billing.change-plan', 'billing.apply-coupon'],
            'roles' => true,
        ],
        [
            'label' => 'Pagamentos',
            'route' => 'settings.payments',
            'match' => ['settings.payments'],
            'roles' => $isManager,
        ],
        [
            'label' => 'WhatsApp',
            'route' => 'whatsapp.settings',
            'match' => ['whatsapp.*'],
            'roles' => true,
        ],
    ];

    if ($isManager) {
        $items[] = [
            'label' => 'Usuários',
            'route' => 'users.index',
            'match' => ['users.*', 'brokers.*'],
            'roles' => true,
        ];
        $items[] = [
            'label' => 'Permissões',
            'route' => 'permissions.index',
            'match' => ['permissions.*'],
            'roles' => true,
        ];
    }
@endphp

<nav class="h-fit rounded-xl border border-slate-200 bg-white p-2 shadow-sm lg:sticky lg:top-6" aria-label="Menu de configurações">
    <p class="px-3 pb-2 pt-1 text-[11px] font-semibold uppercase tracking-wide text-slate-400">Menu</p>
    <ul class="space-y-0.5">
        @foreach ($items as $item)
            @if ($item['roles'])
                @php
                    $active = request()->routeIs(...$item['match']);
                @endphp
                <li>
                    <a
                        href="{{ route($item['route']) }}"
                        @class([
                            'block rounded-lg px-3 py-2 text-sm font-medium transition',
                            'bg-emerald-50 text-emerald-800' => $active,
                            'text-slate-700 hover:bg-slate-50' => ! $active,
                        ])
                    >
                        {{ $item['label'] }}
                    </a>
                </li>
            @endif
        @endforeach
    </ul>
</nav>
