@php
$currentPath = trim(request()->path(), '/');
$currentUrl = rtrim(request()->url(), '/');
$urlMatches = function ($link) use ($currentPath, $currentUrl) {
if (empty($link) || $link === '#') {
return false;
}
$full = str_starts_with($link, 'http') ? rtrim($link, '/') : rtrim(url($link), '/');
$linkPath = trim(parse_url($full, PHP_URL_PATH) ?: '/', '/');
$isRootLink = $linkPath === '' || $linkPath === app()->getLocale();
if ($isRootLink) {
return $currentPath === $linkPath || ($currentPath === '' && $linkPath === '');
}
return $currentPath === $linkPath || str_starts_with($currentPath . '/', $linkPath . '/');
};
@endphp
@foreach ($data['page_init']['menu'] as $item)
@php
$itemLink = $item['href'] ?? ($item['url'] ?? '#');
$isActive = $urlMatches($itemLink);
@endphp
@if ($item['id'] == 6)
@php
$isAllActive = $isActive;
$hasActiveSubmenu = false;
foreach ($data['page_init']['activity_category']['list'] ?? [] as $subitem) {
if ($urlMatches($subitem['url'] ?? '#')) {
$hasActiveSubmenu = true;
break;
}
}
$isActive = $isActive || $hasActiveSubmenu;
@endphp
@else
@endif
@endforeach