{{-- AI Support — IMPULSA skin (chat layout). Left rail: conversation list (pinned AI placeholder + real tickets). Right pane: AI placeholder when nothing selected; full ticket thread when a conversation is selected inline via selectTicket() — no page navigation. Reportar button (next to search) opens the same new-ticket modal. Reply composer supports text + file/image attachments. --}} @php $first = strtoupper(mb_substr(auth()->user()->display_name ?? auth()->user()->name ?? 'U', 0, 1)); $statusTone = ['open' => 'info', 'answered' => 'success', 'customer_reply' => 'warning', 'closed' => 'neutral']; $statusLbl = ['open' => __('Open'), 'answered' => __('Answered'), 'customer_reply' => __('Awaiting'), 'closed' => __('Closed')]; /** * Human-readable label for a ticket in the left rail. * If linked to an order: "Order #134 – Cancel" * Otherwise: "AI Support #16", "Human Support #17", etc. */ $ticketLabel = function (\App\Models\Ticket $t) { if ($t->order_id) { return __('Order') . ' #' . $t->order_id . ' – ' . __($t->category); } return __($t->subject) . ' #' . $t->id; }; @endphp
{{ __('AI Support') }}
{{-- ── LEFT RAIL: conversation list ──────────────────────────────── --}}
{{-- Search + Reportar button --}}
{{-- Pinned AI assistant (always visible, selects to deselect current ticket) --}} {{-- Real ticket conversations --}} @forelse ($tickets as $ticket) @empty

{{ __('No conversations yet.') }}

@endforelse @if ($tickets->hasPages())
{{ $tickets->links() }}
@endif
{{-- ── RIGHT PANE ─────────────────────────────────────────────────── --}}
@if (!$selectedTicket) {{-- ── AI placeholder (no ticket selected) ──────────────── --}}
{{ __('AI Support') }}
{{ __('Online') }}
{{-- Welcome bubble (always shown) --}}
{{ __('Hi :name! 👋 The AI assistant is on its way — for now our human support team will help you.', ['name' => auth()->user()->display_name ?? auth()->user()->name]) }}
@if ($aiMessages->isEmpty())
{{ __('Type your question below and hit Send. To report an order issue, use the red Report button on the left.') }}
@else @foreach ($aiMessages as $msg) @php $isOut = !$msg->is_staff; @endphp
@php $msgAvatar = $msg->user ? $msg->user->avatarUrl() : \App\Support\Avatar::dataUri($msg->is_staff ? __('Support') : 'U'); @endphp
{{ $msg->is_staff ? ($msg->user?->name ?? __('Support')) : ($msg->user?->name ?? __('You')) }} · {{ $msg->created_at?->diffForHumans() }}
{{ $msg->body }}
@if ($msg->attachments)
@foreach ($msg->attachments as $att) @if (str_starts_with($att['mime'] ?? '', 'image/') || ($att['type'] ?? '') === 'image') {{ $att['name'] }} @else {{ $att['name'] }} @endif @endforeach
@endif
@endforeach @endif
{{-- Hidden file input for AI chat --}} {{-- Upload progress --}}
{{-- Pending file chips --}} @if ($aiFiles)
@foreach ($aiFiles as $i => $file)
@if (str_starts_with($file->getMimeType(), 'image/')) @else @endif {{ $file->getClientOriginalName() }}
@endforeach
@endif {{-- Input row --}}
{{-- Attach button --}} {{-- Textarea --}} {{-- Send button --}}
@error('aiBody')

{{ $message }}

@enderror
@else {{-- ── Real ticket thread ────────────────────────────────── --}} @php $tone = ['open' => 'info', 'answered' => 'success', 'closed' => 'neutral', 'pending' => 'warning'][$selectedTicket->status] ?? 'neutral'; @endphp {{-- Thread header --}}
@php $threadAvatarUrl = auth()->user()->avatarUrl(); @endphp @if (str_starts_with($threadAvatarUrl, 'data:'))
{{ $first }}
@else @endif
{{ $ticketLabel($selectedTicket) }}
@if ($selectedTicket->order_id)
{{ __($selectedTicket->subject) }}
@endif
{{ __(ucfirst($selectedTicket->status)) }} @if ($selectedTicket->status !== 'closed') @endif
{{-- Message bubbles --}}
@forelse ($selectedMessages as $msg) @php $isOut = !$msg->is_staff; @endphp {{-- Message row is a direct flex child of rf-imp-chat-body (column). align-self controls left/right alignment; max-width caps total width. row-reverse puts the avatar on the right for outgoing messages. --}}
@php $msgAvatar = $msg->user ? $msg->user->avatarUrl() : \App\Support\Avatar::dataUri($msg->is_staff ? __('Support') : 'U'); @endphp
{{ $msg->is_staff ? ($msg->user?->name ?? __('Support')) : ($msg->user?->name ?? __('You')) }} · {{ $msg->created_at?->diffForHumans() }}
@if (!empty($msg->meta['order_report'])) @php $or = $msg->meta['order_report']; @endphp {{-- Structured order report card --}}
{{ __('Order') }} #{{ $or['order_id'] }}
{{ __('Request') }}: {{ __($or['subcategory']) }}
{{ __('Service') }}: {{ $or['service'] }}
@if (!empty($or['link']))
{{ __('Link') }}: {{ $or['link'] }}
@endif
{{ __('Quantity') }}: {{ number_format($or['quantity']) }}
{{ __('Status') }}: {{ ucfirst($or['status']) }}
{{-- User's actual message below the card --}} @php $msgLine = ''; $parts = preg_split('/\n' . preg_quote(__('Message') . ':', '/') . '\n/u', $msg->body, 2); $msgLine = isset($parts[1]) ? trim($parts[1]) : ''; @endphp @if ($msgLine)
{{ $msgLine }}
@endif @else
{{ $msg->body }}
@endif
{{-- Attachments --}} @if ($msg->attachments)
@foreach ($msg->attachments as $att) @if (($att['type'] ?? '') === 'gif') GIF @elseif (str_starts_with($att['mime'] ?? '', 'image/') || ($att['type'] ?? '') === 'image') {{ $att['name'] }} @else {{ $att['name'] }} @endif @endforeach
@endif
@empty

{{ __('No messages yet.') }}

@endforelse
{{-- Reply composer --}} @if ($selectedTicket->status !== 'closed')
{{-- File upload input (hidden) --}} {{-- Upload progress --}}
{{-- Pending file chips --}} @if ($replyFiles)
@foreach ($replyFiles as $i => $file)
@if (str_starts_with($file->getMimeType(), 'image/')) @else @endif {{ $file->getClientOriginalName() }}
@endforeach
@endif {{-- Input row --}}
{{-- Attach button --}} {{-- Textarea --}} {{-- Send button --}}
@error('replyBody')

{{ $message }}

@enderror
@else
{{ __('This ticket is closed. Open a new one if you still need help.') }}
@endif @endif
{{-- Open the "New Ticket" modal only when the user clicked Report from /app/orders. sessionStorage flag is set by the Report link and cleared here immediately, so a page refresh never re-opens the modal. --}}