@extends('layouts.vendor') @section('page-title', 'Chat System') @push('styles') @endpush @section('content')

Inbox

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

@forelse($chats as $chat) @php $participant = $chat->customer ?? $chat->promoter ?? $chat->admin; $participantType = $chat->customer_id ? 'customer' : ($chat->promoter_id ? 'promoter' : '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 === '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
@if($activeChat) @php $participant = $activeChat->customer ?? $activeChat->promoter ?? $activeChat->admin; $participantType = $activeChat->customer_id ? 'customer' : ($activeChat->promoter_id ? 'promoter' : 'admin'); $initial = $participant ? substr($participant->name, 0, 1) : '?'; $avatarClass = $participantType === 'customer' ? 'bg-blue-50 text-blue-600' : ($participantType === 'promoter' ? 'bg-purple-50 text-purple-600' : 'bg-red-50 text-red-600'); $badgeClass = 'badge-' . $participantType; @endphp
{{ $initial }}

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

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

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

@endif
@csrf
@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
@csrf
@else

Select a conversation

Choose from the sidebar to start messaging

@endif
@if($activeChat) @endif @endsection