@php /** @var \Illuminate\Support\Collection|\Illuminate\Database\Eloquent\Collection $messages */ $messages = $messages ?? collect(); $users = $users ?? collect(); $responsibleUserIds = array_map('intval', $responsibleUserIds ?? []); $managerUserId = isset($managerUserId) ? (int) $managerUserId : null; $brigadierUserId = isset($brigadierUserId) ? (int) $brigadierUserId : null; $currentUserId = (int) auth()->id(); $contextKey = $contextKey ?? 'chat'; $title = $title ?? 'Чат'; $submitLabel = $submitLabel ?? 'Отправить'; $canSendNotifications = hasRole('admin,manager'); $canDeleteMessages = hasRole('admin') && !empty($action); $notificationValue = old('notification_type', \App\Models\ChatMessage::NOTIFICATION_NONE); $notificationEnabled = $canSendNotifications && $notificationValue !== \App\Models\ChatMessage::NOTIFICATION_NONE; $showAllUsers = $notificationValue === \App\Models\ChatMessage::NOTIFICATION_ALL; $selectedTargetUserIds = collect(old('target_user_ids', [])) ->map(static fn ($id) => (int) $id) ->filter() ->unique() ->values() ->all(); // Роли в порядке сортировки $roleOrder = [\App\Models\Role::ADMIN, \App\Models\Role::MANAGER, \App\Models\Role::BRIGADIER]; $roleNames = \App\Models\Role::NAMES; // Сортировка пользователей: админы -> менеджеры -> бригадиры -> остальные $sortedUsers = $users->sortBy(function ($user) use ($roleOrder) { $role = $user['role'] ?? ''; $index = array_search($role, $roleOrder, true); return $index === false ? 999 : $index; }); @endphp