{{-- Mail filter toolbar. Extracted from layouts.app and now rendered only on mail routes — it used to appear on Domain, Department and Employee screens, where mail sentiment and promotion counts mean nothing. Expects: $counts — mail count array from MailController::common() $employee — set when an admin is viewing another user's mailbox --}} @php // Which filter is currently being viewed — used to highlight the active chip. // Null on routes that have no {type} parameter (e.g. mail.info), which is what we want. $activeFilter = request()->route('type'); $replyGroup = ['send-mail', 'replied_mail']; $groupByGroup = ['sales', 'amc']; // Sentiment is admin-managed, so the dropdown, its counts and the set of // slugs that light the chip up all come from the configured vocabulary. $sentimentDefs = $counts['sentiment_defs'] ?? []; $sentimentCounts = $counts['sentiments'] ?? []; $sentimentGroup = array_keys($sentimentDefs); $sentimentTotal = $counts['sentimentTotal'] ?? array_sum($sentimentCounts); // Next actions work the same way. The menu is the "what needs doing" panel: // one row per action, most urgent first, each opening its own listing. $nextActionDefs = $counts['next_action_defs'] ?? []; $nextActionCounts = $counts['next_actions'] ?? []; $nextActionGroup = array_column($nextActionDefs, 'slug'); // Everything except the "nothing to do" action — the chip is a workload // figure, and counting mail that needs nothing would flatter it. $nextActionOutstanding = collect($nextActionDefs) ->reject(fn($def) => $def['code'] === 'no_action') ->sum(fn($def) => $nextActionCounts[$def['slug']] ?? 0); // Categories are admin-managed too, and per account. Sales and AMC stay // where they are at the top of this menu: they read messages.category, the // coarse number several categories share, and both have been bookmarkable // for years. The rows beneath them are the specific codes the same // classification produced. $categoryDefs = $counts['category_defs'] ?? []; $categoryCounts = $counts['categories'] ?? []; $groupByGroup = array_merge($groupByGroup, array_column($categoryDefs, 'slug')); // Leads. The chip opens every lead; the menu splits them by type. The // headline figure comes from the vocabulary's own all-leads key rather than // a sum, so a mail typed under a retired lead type is still counted. $leadDefs = $counts['lead_defs'] ?? []; $leadCounts = $counts['leads'] ?? []; $allLeadsSlug = \App\Models\LeadType::ALL_LEADS_SLUG; $leadGroup = array_merge([$allLeadsSlug], array_column($leadDefs, 'slug')); $leadTotal = $counts['leadTotal'] ?? ($leadCounts[$allLeadsSlug] ?? 0); // Priority bands, in the same chip and above the per-type rows: "which of // these do I do first" is the question people arrive at the Leads menu // with far more often than "show me the demo requests". $leadPriorityDefs = $counts['lead_priority_defs'] ?? []; $leadPriorityCounts = $counts['lead_priorities'] ?? []; $leadGroup = array_merge($leadGroup, array_column($leadPriorityDefs, 'slug')); // Assignment. Teams come from `departments` rather than a vocabulary, so // the rows are this account's org chart; the three fixed rows are the ones // that belong to no team. // // The chip's own figure is "assigned to me", not the total assigned, and // the chip links there. Everything else in this toolbar answers a question // about the mailbox; this one answers "what is mine", which is the only // question most people open it with — and it is the row that spans // mailboxes, because work does not arrive where the person is. $assignmentDefs = $counts['assignment_defs'] ?? []; $assignmentCounts = $counts['assignments'] ?? []; $mineSlug = \App\Models\Department::MINE_SLUG; $assignmentGroup = array_column($assignmentDefs, 'slug'); $assignmentTeams = array_filter($assignmentDefs, fn($def) => $def['kind'] === 'department'); $assignmentPeople = array_filter($assignmentDefs, fn($def) => $def['kind'] === 'person'); $mineTotal = $assignmentCounts[$mineSlug] ?? 0; $toolbarUserId = isset($employee) ? $employee->id : Auth::id(); // Whose queue this row shows: the mailbox on the URL when the viewer may // read it, otherwise their own — Department::assignmentSubjectId(), the same // call the listing and the count make. $mineSubjectId = \App\Models\Department::assignmentSubjectId( Auth::id(), \App\Models\Department::ownerIdFor(Auth::id()), $toolbarUserId, ); $mineSubjectName = $mineSubjectId === (int) Auth::id() ? null : (\App\Models\Department::assigneeNamesFor(Auth::id())[$mineSubjectId] ?? null); $mineLabel = $mineSubjectName ? 'Assigned to ' . $mineSubjectName : 'Assigned to me'; $mineHint = $mineSubjectName ? 'Everything assigned to ' . $mineSubjectName . ', across every mailbox in this account' : 'Mail assigned to you, across every mailbox in this account'; // Build filter URLs through one helper instead of repeating the // isset($employee) ternary on every chip. $filterUrl = fn($type) => isset($employee) ? route('mails.filter', [$type, $employee->id]) : route('mails.filter', [$type]); @endphp @if (Auth::check() && Auth::user()->auth_id == 0) @endif