@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

{{ $title }}
@forelse($messages as $message)
{{ $message->user?->name ?? 'Пользователь' }} @if($message->notification_type === \App\Models\ChatMessage::NOTIFICATION_USER && $message->targetUser) для {{ $message->targetUser->name }} @elseif(in_array($message->notification_type, [\App\Models\ChatMessage::NOTIFICATION_RESPONSIBLES, \App\Models\ChatMessage::NOTIFICATION_ALL], true)) Уведомления: {{ $message->notifiedUsers->pluck('name')->join(', ') ?: 'получатели' }} @endif
{{ $message->created_at?->format('d.m.Y H:i') }} @if($canDeleteMessages)
@csrf
@endif
@if(!empty($message->message))
{{ $message->message }}
@endif @if($message->files->isNotEmpty())
@foreach($message->files as $file) @if(\Illuminate\Support\Str::startsWith((string) $file->mime_type, 'image/')) {{ $file->original_name }} @else {{ $file->original_name }} @endif @endforeach
@endif
@empty
Сообщений пока нет.
@endforelse
@csrf {{-- Уведомления: свитч + саммари --}} @if($canSendNotifications) {{-- Скрытый select для notification_type (значение управляется JS) --}} @else @endif {{-- Строка ввода: textarea + иконка файла + кнопка отправить --}}
@foreach($selectedTargetUserIds as $selectedTargetUserId) @endforeach
@if($canSendNotifications) @endif
@once @push('scripts') @endpush @endonce