@php $cpItem = (array) ($item ?? []); $cpLevel = (int) ($level ?? 0); $cpChildren = array_values((array) data_get($cpItem, 'children', [])); $cpUrl = trim((string) data_get($cpItem, 'url', '#')) ?: '#'; $cpTitle = trim((string) data_get($cpItem, 'title', 'Menu')) ?: 'Menu'; $cpTarget = (string) data_get($cpItem, 'target', '_self'); $cpCurrent = (string) ($currentUrl ?? ''); $cpComparable = rtrim($cpUrl, '/'); $cpActive = $cpComparable !== '' && $cpComparable !== '#' && ($cpCurrent === $cpComparable || str_starts_with($cpCurrent.'/', $cpComparable.'/')); $cpHasChildren = $cpChildren !== []; @endphp