@props(['s'])
@php
// Defensive guard: skip the whole entry if its `list` route isn't
// registered. The sidebar config lists every admin surface (incl.
// optional ones like the AI dashboard) but production may be on a
// commit where some controllers haven't been deployed yet — the
// page should not 500 just because a sidebar link points to a
// future route.
if (empty($s['list']) || ! \Illuminate\Support\Facades\Route::has($s['list'])) {
return;
}
if (! empty($s['permission']) && ! \Illuminate\Support\Facades\Auth::guard('admin')->user()?->can($s['permission'])) {
return;
}
$adminUser = \Illuminate\Support\Facades\Auth::guard('admin')->user();
$routePermission = function (string $routeName) {
$route = \Illuminate\Support\Facades\Route::getRoutes()->getByName($routeName);
return $route ? \App\Support\Admin\AdminPermissionRegistry::permissionForRoute($route) : null;
};
$listPermission = $routePermission($s['list']);
$canList = $listPermission && $adminUser?->can($listPermission);
// `create` is optional even when supplied — drop the link if its
// route is also missing rather than crashing the group.
$hasCreate = ! empty($s['create']) && \Illuminate\Support\Facades\Route::has($s['create'])
&& ($createPermission = $routePermission($s['create'])) && $adminUser?->can($createPermission);
// Extra sub-links for a module that belongs INSIDE this menu rather than
// beside it — same missing-route guard as the entry itself.
$children = array_values(array_filter(
$s['children'] ?? [],
fn ($c) => ! empty($c['list']) && \Illuminate\Support\Facades\Route::has($c['list'])
&& ($permission = $routePermission($c['list'])) && $adminUser?->can($permission),
));
// A child's own page must open and light up its parent group, otherwise
// the menu collapses out from under the page the admin is looking at.
$childPatterns = array_map(fn ($c) => $c['route'] ?? $c['list'], $children);
$patterns = is_array($s['route']) ? $s['route'] : [$s['route']];
$active = request()->routeIs(...$patterns)
|| ($childPatterns !== [] && request()->routeIs(...$childPatterns));
if (($s['mode'] ?? 'direct') === 'direct' && ! $canList) return;
if (($s['mode'] ?? 'direct') !== 'direct' && ! $canList && $children === []) return;
$collapsedRoute = $canList ? $s['list'] : $children[0]['list'];
@endphp
@if (($s['mode'] ?? 'direct') === 'direct')