@extends('layouts.admin') @section('page-title', 'Chat System') @push('styles') @endpush @section('content')
{{-- Sidebar --}}

Inbox

{{ $chats->count() }} conversations

@forelse($chats as $chat) @php $participant = $chat->customer ?? $chat->promoter ?? $chat->vendor ?? $chat->admin; $participantType = $chat->customer_id ? 'customer' : ($chat->promoter_id ? 'promoter' : ($chat->vendor_id ? 'vendor' : 'admin')); $initial = $participant ? substr($participant->name, 0, 1) : '?'; $lastMessage = $chat->messages()->latest()->first(); $unreadCount = $chat->messages()->where('is_read', false)->where('sender_id', '!=', auth()->id())->count(); $isActive = isset($activeChat) && $chat->id === $activeChat->id; $avatarClass = $participantType === 'customer' ? 'bg-blue-50 text-blue-600' : ($participantType === 'vendor' ? 'bg-emerald-50 text-emerald-600' : ($participantType === 'promoter' ? 'bg-purple-50 text-purple-600' : 'bg-red-50 text-red-600')); $badgeClass = 'badge-' . $participantType; @endphp
{{ $initial }}
@if($unreadCount > 0) @endif

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

@if($lastMessage) {{ $lastMessage->created_at->diffForHumans(short: true) }} @endif
@if($lastMessage)

{{ Str::limit($lastMessage->message ?: 'Sent an image', 35) }}

@elseif($chat->product)

{{ $chat->product->name }}

@endif @if($unreadCount > 0) {{ $unreadCount }} @endif
@empty

No conversations

Start a new chat to begin messaging

@endforelse
{{-- Chat Area --}}
@if($activeChat) @php $participant = $activeChat->customer ?? $activeChat->promoter ?? $activeChat->vendor ?? $activeChat->admin; $participantType = $activeChat->customer_id ? 'customer' : ($activeChat->promoter_id ? 'promoter' : ($activeChat->vendor_id ? 'vendor' : 'admin')); $initial = $participant ? substr($participant->name, 0, 1) : '?'; $avatarClass = $participantType === 'customer' ? 'bg-blue-50 text-blue-600' : ($participantType === 'vendor' ? 'bg-emerald-50 text-emerald-600' : ($participantType === 'promoter' ? 'bg-purple-50 text-purple-600' : 'bg-red-50 text-red-600')); $badgeClass = 'badge-' . $participantType; @endphp {{-- Header --}}
{{ $initial }}

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

{{ $participantType }}
@if($activeChat->product)

{{ $activeChat->product->name }}

@endif
@csrf
{{-- Messages --}}
@foreach($activeChat->messages()->with('sender')->orderBy('created_at')->get() as $message)
@if($message->sender_id !== auth()->id()) @php $msgInitial = $message->sender ? substr($message->sender->name, 0, 1) : '?'; @endphp

{{ $message->sender?->name }}

@endif
@if($message->message)

{{ $message->message }}

@endif @if($message->attachments) @foreach(json_decode($message->attachments) as $image) @endforeach @endif

{{ $message->created_at->format('h:i A') }}

@endforeach
{{-- Input --}}
@csrf
@else

Select a conversation

Choose from the sidebar to start messaging

@endif
@if($activeChat) @endif {{-- New Chat Modal --}} @endsection