{{-- Two-column chat layout: inbox sidebar (md+) + chat window. Uses position:fixed to escape the pt-16 pb-24 wrapper and fill exactly the space between the navbar (4rem) and bottom bar (4rem). --}}
{{-- ── LEFT: Inbox sidebar (desktop only) ────────────────────────────── --}} {{-- Alpine component: chatWindow ───────────────────────────────────────────────────────────────────── Adaptive polling state machine: ACTIVE → poll every 4s (user typed/clicked in the last 10s) IDLE → poll every 12s (tab visible, no recent activity) BACKGROUND → poll every 20s (Page Visibility API: tab hidden) Only fetches new messages (delta: id > lastMessageId). Never reloads the full conversation. --}} {{-- ── RIGHT: Chat window ─────────────────────────────────────────────── --}}
{{-- ── Compact chat header ────────────────────────────────────────── --}}
{{-- Back to inbox (mobile only) --}} {{-- Avatar --}} @if ($other?->primaryPhoto) {{ $other->name }} @elseif ($other)
{{ mb_substr($other->name, 0, 1) }}
@else
@endif

{{ $other?->name ?? __('Deleted account') }} @if ($other?->profile) #{{ $other->id }} @endif

{{-- ⋮ Context menu --}}
@php $menuItem = 'flex items-center gap-3 w-full px-4 py-2.5 text-left text-gray-700 dark:text-gray-200 hover:bg-gray-50 dark:hover:bg-gray-700 transition'; $menuItemDanger = 'flex items-center gap-3 w-full px-4 py-2.5 text-left text-red-600 dark:text-red-400 hover:bg-red-50 dark:hover:bg-gray-700 transition'; $divider = 'my-1 border-t border-gray-100 dark:border-gray-700'; @endphp {{-- View profile --}} @if ($other?->profile) {{ __('View profile') }} @endif {{-- Report --}} @if ($other) {{ __('Report') }} @endif {{-- Unblock (block is now in the mood picker) --}} @if ($other && auth()->user()->is_premium && $isBlocked)
@csrf @method('DELETE')
@endif
{{-- Clear history --}}
@csrf
{{-- Delete chat --}}
@csrf @method('DELETE')
{{-- ── Lightbox overlay ───────────────────────────────────────────── --}}
{{-- Top bar --}}

{{-- spacer to visually centre the filename --}}
{{-- Image area — click backdrop to close --}}
{{-- ── Message list ────────────────────────────────────────────────── --}}
{{-- Server-rendered initial messages (last 50, oldest first) --}} @php $moodLabels = [ 'happy' => '😊 ' . __('Happy'), 'relaxed' => '😌 ' . __('Relaxed'), 'neutral' => '😐 ' . __('Neutral'), 'low_energy' => '🪫 ' . __('Low energy'), 'uncomfortable' => '😬 ' . __('Uncomfortable'), 'overstimulated' => '🌊 ' . __('Overstimulated'), 'done' => '🛑 ' . __('Want to stop'), ]; @endphp @foreach ($messages as $msg) @if ($msg->type === 'mood_change') {{-- Mood event pill --}} @php $isMineEvent = $msg->sender_id === auth()->id(); $eventName = $msg->sender?->name ?? __('Someone'); $moodKey = $msg->message ?? ''; $moodText = $moodLabels[$moodKey] ?? __('no mood set'); @endphp
{{ $eventName }} {{ __('is feeling') }}: {{ $moodText }} ·
@else @php $isMine = $msg->sender_id === auth()->id(); @endphp
{{-- Reply button (left side for own messages) --}} @if ($isMine) @endif
{{-- Quote block --}} @if ($msg->replyTo)

{{ $msg->replyTo->sender?->name ?? __('Deleted user') }}

{{ Str::limit(strip_tags($msg->replyTo->message ?? '📎'), 80) }}

@endif {{-- Attachment card --}} @if ($msg->attachment_name) @php $hasOriginal = (bool) $msg->attachment; $openUrl = $hasOriginal ? route('chat.attachments.show', $msg->id) : null; $dlUrl = $hasOriginal ? route('chat.attachments.show', $msg->id) . '?download=1' : null; $thumbUrl = $msg->thumbnail ? route('chat.attachments.thumb', $msg->id) : null; $expiresLabel = $msg->attachment_expires_at ? ($hasOriginal ? __('Expires') . ' ' . $msg->attachment_expires_at->format('d-m-Y') : __('Deleted on') . ' ' . $msg->attachment_expires_at->format('d-m-Y')) : null; @endphp @if ($msg->attachment_type === 'image' && $thumbUrl) {{-- Image card with thumbnail --}}
@if ($openUrl) @else
{{ $msg->attachment_name }}
{{ __('Original deleted') }}
@endif

{{ $msg->attachment_name }}

@if ($expiresLabel)

{{ $expiresLabel }}

@endif
@if ($openUrl) {{ __('Download') }} @endif @if ($isMine) @endif
@else {{-- Non-image (or image without thumbnail) file card --}}

{{ $msg->attachment_name }}

@if ($expiresLabel)

{{ $expiresLabel }}

@endif
@if ($openUrl) {{ __('Open') }} {{ __('Download') }} @endif @if ($isMine) @endif
@endif @endif @if ($msg->message) {!! \App\Helpers\ChatHelper::linkify($msg->message) !!} @endif

{{-- Reply button (right side for others' messages) --}} @if (!$isMine) @endif {{-- Delete button (right side for own messages) --}} @if ($isMine) @endif
@endif {{-- mood_change --}} @endforeach {{-- Dynamically appended messages via polling / send --}}
{{-- ── Input area ──────────────────────────────────────────────────── --}}
@if ($isBlocked) {{-- User is blocked: show a clear notice so they know why they can't send. --}}

{{ __('You have blocked :name. Unblock them to send messages.', ['name' => $other?->name]) }}

@elseif (!$isMatched) {{-- No mutual like (e.g. after unblocking — likes were removed on block). --}}

{{ __('You are no longer matched. Like each other again to restart the chat.') }}

@elseif (!auth()->user()->is_premium && $freeMessagesUsed >= $freeMessagesLimit) {{-- Server-side: free user hit the limit on page load. --}}

{{ __("You've used all :limit free messages.", ['limit' => $freeMessagesLimit]) }}

{{ __('Upgrade to Premium for unlimited chat') }} →
@else {{-- Client-side: limit reached during this session (messageLimitReached flag). --}} {{-- Free-plan message counter --}} @if (!auth()->user()->is_premium) @php $remaining = $freeMessagesLimit - $freeMessagesUsed; @endphp @endif {{-- Reply bar --}} {{-- Attachment preview bar --}}
{{-- Attachment button --}}
{{-- Send error toast --}} {{-- Mood bar --}}
{{-- Mood picker (opens upward) --}}
@endif {{-- $isMatched --}}
@push('bottom-bar-buttons') {{-- Normal chat nav: Inbox + bell (hidden while lightbox is open) --}}
{{-- Inbox link shown on mobile only (sidebar handles desktop) --}} {{ __('Inbox') }} {{-- Browser notification toggle --}} @include('partials.bell-toggle')
{{-- Lightbox back button (hidden until lightbox opens) --}} @endpush @push('scripts') @endpush