@if(!$conversation) {{-- Empty state: select a conversation --}}

{{ __('Select a conversation') }}

{{ __('Choose a conversation from the list to view its messages and collaborate with your team.') }}

@else
{{-- AI Setup Warning Banner --}} @if(!$this->isAiConfigured)

{{ __('AI replies not configured') }}

{{ __('Set up AI to get smart reply suggestions for your conversations.') }}

{{ __('Set Up AI') }}
@endif {{-- Header actions --}}
{{-- Back button (mobile) --}} {{-- More actions button --}}
{{-- Contact name + status --}}
@php $avatarColors = ['bg-pink-500/20 text-pink-400', 'bg-blue-500/20 text-blue-400', 'bg-emerald-500/20 text-emerald-400', 'bg-amber-500/20 text-amber-400', 'bg-violet-500/20 text-violet-400']; $colorIndex = ($conversation->contact_id ?? 0) % count($avatarColors); @endphp
{{ $conversation->contact?->initials ?? '??' }}
{{ $conversation->contact?->full_name ?? __('Unknown') }} {{-- Status --}} @php $statusColors = [ 'open' => 'bg-green-500/10 text-green-400 border-green-500/20', 'closed' => 'bg-white/5 text-gray-500 border-white/10', 'pending' => 'bg-yellow-500/10 text-yellow-400 border-yellow-500/20', 'snoozed' => 'bg-blue-500/10 text-blue-400 border-blue-500/20', 'spam' => 'bg-orange-500/10 text-orange-400 border-orange-500/20', ]; $sColor = $statusColors[$conversation->status] ?? $statusColors['open']; @endphp {{ ucfirst($conversation->status) }} {{-- Channel --}} {{ ucfirst($conversation->channel ?? __('Email')) }}
{{-- Toggle right panel --}}
{{-- Content Area Scrollable --}}
{{-- Subject --}}

{{ $conversation->subject ?? __('(no subject)') }}

{{-- Tags inline --}} @if($conversation->tagModels->isNotEmpty())
@foreach($conversation->tagModels as $tag) {{ $tag->name }} @endforeach
@endif {{-- Assigned to --}} @if($conversation->assignedTo)

{{ __('Assigned to') }} {{ $conversation->assignedTo->name }}

@endif {{-- Messages --}}
@foreach($messages as $index => $message) {{-- Date divider --}} @if($index === 0 || !$message->created_at->isSameDay($messages[$index - 1]->created_at ?? now())) @endif
@if($message->type === 'note') {{-- Internal Note --}}
{{ __('Internal Note') }} {{ $message->sender?->name ?? __('Unknown') }} {{ $message->created_at->diffForHumans() }}
{!! $message->safe_body_html !!}

{{ __('(This note is only visible to your team)') }}

@elseif($message->type === 'ai_draft' && $message->ai_status === 'draft') {{-- AI Draft Pending Approval --}}
{{ __('AI Draft -- Pending Your Approval') }}
{!! $message->safe_body_html !!}
@if($message->ai_confidence) {{ __('Confidence:') }} {{ $message->ai_confidence }}% @endif
@elseif($message->sender_type === 'ai') {{-- AI Message --}}
{{ $message->created_at->diffForHumans() }} {{ __('via') }} {{ ucfirst($conversation->channel ?? __('email')) }} {{ __('AI Assistant') }} {{ __('AI') }}
{!! $message->safe_body_html !!}
{{ __('AI Generated') }} @if($message->ai_confidence) {{ __('Confidence:') }} {{ $message->ai_confidence }}% @endif
@elseif($message->direction === 'outbound') {{-- Outgoing Message (right-aligned, blue tint) --}}
{{ $message->sender?->initials ?? __('Me') }}
{{ $message->created_at->diffForHumans() }} {{ __('via') }} {{ ucfirst($conversation->channel ?? __('email')) }} {{ $message->sender?->name ?? __('You') }}
@php $realAttachments = $message->attachments?->filter(fn ($a) => empty($a->content_id)) ?? collect(); @endphp @if($realAttachments->isNotEmpty())
@foreach($realAttachments as $attachment)
{{ $attachment->original_filename }} {{ $attachment->size_for_humans }}
@endforeach
@endif
{{ __('Sent') }}
@else {{-- Incoming Message --}}
{{ $conversation->contact?->initials ?? '??' }}
{{ $message->senderName ?? $conversation->contact?->full_name ?? __('Unknown') }} {{ __('via') }} {{ ucfirst($conversation->channel ?? __('email')) }} {{ $message->created_at->diffForHumans() }}
@if($message->subject && $message->subject !== $conversation->subject && $index === 0)
{{ $message->subject }}
@endif @if($message->from_email)
{{ __('From:') }} {{ $message->from_name ?? '' }} <{{ $message->from_email }}> @if($message->to_emails) {{ __('To:') }} {{ is_array($message->to_emails) ? implode(', ', $message->to_emails) : $message->to_emails }} @endif {{ $message->created_at->format('M j, Y \\a\\t g:i A') }}
@endif
@php $realAttachments = $message->attachments?->filter(fn ($a) => empty($a->content_id)) ?? collect(); @endphp @if($realAttachments->isNotEmpty())
@foreach($realAttachments as $attachment)
{{ $attachment->original_filename }} {{ $attachment->size_for_humans }}
@endforeach
@endif @if($message->sentiment && $message->direction === 'inbound') @php $sentimentStyle = match($message->sentiment) { 'positive' => 'text-green-400 bg-green-500/10', 'negative' => 'text-red-400 bg-red-500/10', default => 'text-gray-500 bg-white/5', }; @endphp
{{ ucfirst($message->sentiment) }}
@endif
@endif
@endforeach @if($messages->isEmpty())

{{ __('No messages in this conversation yet.') }}

@endif
{{-- AI loading indicator --}} @if($aiLoading ?? false)
{{ __('Generating AI reply...') }}
@endif {{-- Reply Composer with toggle --}}
{{-- Right Panel: Conversation Details --}} @endif