{{-- Shared application sidebar. Included by both layouts (layouts.app and setting.nav) so every screen in the app carries the same navigation. Previously each layout shipped its own navbar, which is why Mail pages and Settings pages looked like two products. Expects (all optional): $counts — the mail count array built by MailController::common() $employee — set when an admin is viewing another user's mailbox --}} @php $currentRoute = Route::currentRouteName(); // An admin is auth_id === 0; everyone else sees the reduced menu. $isAdmin = Auth::check() && Auth::user()->auth_id == 0; $sidebarCounts = $counts ?? []; // The mail controllers set $employee when an admin is viewing another // person's mailbox. Do not trust the name alone: @extends hands the layout // everything get_defined_vars() returns, so a child view's @foreach // ($employees as $employee) leaves a leftover row of a different shape in // scope (employee/admin_group.blade.php does exactly that). Check that the // object actually carries a mailbox before treating it as one. $viewedMailbox = isset($employee) && is_object($employee) && isset($employee->email, $employee->id, $employee->account_type) ? $employee : null; // The account footer is the one place anyone reads "who am I", so it always // names the signed-in account. It used to fall back the other way round — // $viewedMailbox first — which meant an admin browsing an employee's mailbox // saw the employee's address AND their Google/Microsoft badge in the footer, // and reasonably read it as being signed in as that person. // // That misreading is expensive because "Assigned to me" is keyed to // Auth::id() (Department::applyAssignmentFilter), not to the mailbox in the // URL. An owner viewing an employee's mailbox therefore sees an empty // "Assigned to me" while the footer names the employee the mail is actually // assigned to — which looks exactly like the assignment failed to save. $sidebarEmail = Auth::user()?->email ?? 'Guest'; $sidebarAccountType = Auth::user()?->account_type ?? null; // The mailbox being viewed is still shown — as its own line that says it is // a mailbox, rather than standing in for the identity. $sidebarViewingEmail = $viewedMailbox && $viewedMailbox->email !== $sidebarEmail ? $viewedMailbox->email : null; $mailInfoUrl = $viewedMailbox ? route('mail.info', $viewedMailbox->id) : route('mail.info'); // Route names that should light up each nav entry. The mail entry stays lit // while the user is inside any mail view (list, single mail, reply). $navActive = function (array $routes) use ($currentRoute) { return in_array($currentRoute, $routes, true) ? 'is-active' : ''; }; @endphp