get('user_name') ?? '')); $userEmail = trim((string) (session()->get('user_email') ?? '')); $rawRole = session()->get('role'); $allRoles = array_map(fn($r)=> strtolower(trim((string)$r)), (array) (session()->get('roles') ?? [])); $currentRole = strtolower((string) ($rawRole ?? 'guest')); $otherRoles = array_values(array_filter($allRoles, fn($r) => $r !== '' && $r !== $currentRole)); // Compute initials from name, fallback to email/letter U $initials = 'U'; if ($userName !== '') { $parts = preg_split('/\s+/', $userName); $first = $parts[0] ?? ''; $last = count($parts) > 1 ? end($parts) : ''; $initials = strtoupper(substr($first, 0, 1) . ($last !== '' ? substr($last, 0, 1) : '')); } elseif ($userEmail !== '') { $initials = strtoupper(substr($userEmail, 0, 1)); } // Style palettes $styleCfg = config('Style'); $sess = session(); $currentAccent = $sess->get('style_color') ?? ($styleCfg->defaultStyle ?? 'blue'); $currentMenu = $sess->get('menu_color') ?? ($styleCfg->defaultMenu ?? 'white'); // Build current menu palette (supports custom) if ($currentMenu === 'custom') { $menuLP = [ 'bg' => (string)($sess->get('menu_custom_bg') ?? '#0f172a'), 'text' => (string)($sess->get('menu_custom_text') ?? '#ffffff'), 'mode' => (string)($sess->get('menu_custom_mode') ?? 'dark'), ]; } else { $menuLP = $styleCfg->menuPalettes[$currentMenu] ?? ($styleCfg->menuPalettes[$styleCfg->defaultMenu] ?? [ 'bg' => '#ffffff', 'text' => '#334155', 'mode' => 'light']); } $resolveMenuMode = function (string $mode, string $bg): string { $mode = strtolower(trim($mode)); if ($mode === 'light' || $mode === 'dark') return $mode; $hex = ltrim(trim($bg), '#'); if (strlen($hex) === 3) { $hex = $hex[0].$hex[0].$hex[1].$hex[1].$hex[2].$hex[2]; } if (strlen($hex) !== 6) return 'dark'; $r = hexdec(substr($hex, 0, 2)); $g = hexdec(substr($hex, 2, 2)); $b = hexdec(substr($hex, 4, 2)); $lum = (0.2126 * $r + 0.7152 * $g + 0.0722 * $b) / 255.0; return ($lum < 0.5) ? 'dark' : 'light'; }; $headerMode = $resolveMenuMode((string)($menuLP['mode'] ?? 'light'), (string)($menuLP['bg'] ?? '#0f172a')); $headerModeCls = ($headerMode === 'dark') ? 'navbar-dark' : 'navbar-light'; ?>