@extends('layouts.app') @section('title', 'WhatsApp Conversation') @push('styles') @endpush @section('content') @php $state = $conversation->state ?? 'idle'; $stateClass = 'state-' . $state; $customerName = $conversation->customer?->name; $ctx = is_array($conversation->context ?? null) ? $conversation->context : (is_string($conversation->context ?? null) ? (json_decode($conversation->context, true) ?: []) : []); @endphp @if(session('success'))
{{ session('success') }}
@endif @if(session('error'))
{{ session('error') }}
@endif
@if(isset($conversation->messages) && $conversation->messages->count()) @foreach($conversation->messages as $msg) @php $dir = $msg->direction ?? 'inbound'; $dirClass = $dir === 'outbound' ? 'outbound' : 'inbound'; @endphp
{{ $msg->body }}
{{ $msg->created_at->format('M j, H:i') }}
@endforeach @else
No messages yet in this conversation.
@endif
@if(!$tenant->wa_enabled)
Enable WhatsApp in settings to reply.
@endif
@csrf
Reply will be sent via WhatsApp Business API.

Customer

@if($conversation->customer) @php $c = $conversation->customer; $rs = (int) ($c->risk_score ?? 0); $rBand = $rs >= 70 ? 'high' : ($rs >= 40 ? 'medium' : 'low'); $rColor = $rBand === 'high' ? 'var(--danger)' : ($rBand === 'medium' ? 'var(--warning)' : 'var(--success)'); @endphp
Phone {{ $c->phone ?? $conversation->phone ?? '—' }}
Email {{ $c->email ?? '—' }}
@if(!empty($c->tag))
Tag {{ $c->tag }}
@endif @if($rs > 0)
Risk Score {{ $rs }}/100 · {{ ucfirst($rBand) }}
@endif
@else
Phone {{ $conversation->phone ?? '—' }}
No customer record linked yet.
@endif

Last Order

@if($conversation->last_order_id && $conversation->lastOrder) @php $lo = $conversation->lastOrder; @endphp
@if(isset($lo->total))
Total ₦{{ number_format((float) $lo->total, 2) }}
@endif @if(isset($lo->status))
Status {{ str_replace('_', ' ', $lo->status) }}
@endif @if(isset($lo->created_at))
Placed {{ \Carbon\Carbon::parse($lo->created_at)->format('M j, Y · H:i') }}
@endif
@else
No orders placed through this conversation yet.
@endif

State & Context

Current State {{ str_replace('_', ' ', $state) }}
Last Message {{ $conversation->last_message_at ? \Carbon\Carbon::parse($conversation->last_message_at)->diffForHumans() : '—' }}
Context @if(!empty($ctx) && is_array($ctx))
@foreach($ctx as $k => $v)
{{ str_replace('_', ' ', $k) }} {{ is_scalar($v) ? (string) $v : json_encode($v) }}
@endforeach
@else
No context data.
@endif
@endsection @push('scripts') @endpush