@extends('layouts.app') @section('title', 'Messages') @section('page-title', 'Messages') @section('content')
{{-- LEFT: Conversations List --}}

Conversations

@forelse($conversations as $conv) @php $other = $conv->participants->where('id', '!=', auth()->id())->first(); $lastMsg = $conv->latestMessage; $unread = false; $pivot = $conv->participants->where('id', auth()->id())->first()?->pivot; if ($lastMsg && $pivot) { $unread = !$pivot->last_read_at || $lastMsg->created_at->gt($pivot->last_read_at); } $childrenInfo = $other?->_children_info ?? null; @endphp
{{ strtoupper(substr($other->name ?? '?', 0, 1)) }}{{ strtoupper(substr(explode(' ', $other->name ?? '')[1] ?? '', 0, 1)) }}

{{ $other->name ?? 'Unknown' }}

{{ $lastMsg?->created_at?->diffForHumans(short: true) ?? '' }}
{{ $other->role ?? '' }} @if($childrenInfo) {{ $childrenInfo }} @endif

@if($lastMsg) {{ $lastMsg->sender_id === auth()->id() ? 'You: ' : '' }}{{ Str::limit($lastMsg->message, 50) }} @else No messages yet @endif

@if($unread)
@endif
@empty

No conversations yet

Start a new message to begin chatting

@endforelse
@if($conversations->hasPages())
{{ $conversations->links() }}
@endif
{{-- RIGHT: Contacts Panel --}}

Contacts

Click to start a conversation

@forelse($contacts as $group => $members)

{{ $group }}

@foreach($members as $contact) @endforeach
@empty
No contacts available
@endforelse
{{-- New Message Modal --}} @endsection