@php
    $labels = [
        'user' => 'User',
        'bnfexpress_ev_agent' => 'Assistant',
    ];
@endphp

<div class="max-h-[32rem] space-y-3 overflow-y-auto">
    @forelse (($transcript['messages'] ?? []) as $message)
        @php
            $author = $message['author'] ?? 'unknown';
            $isUser = $author === 'user';
        @endphp
        <div @class([
            'max-w-[85%] rounded-lg border p-3',
            'ms-auto border-primary-200 bg-primary-50 dark:border-primary-800 dark:bg-primary-950' => $isUser,
            'border-gray-200 bg-gray-50 dark:border-gray-700 dark:bg-gray-800' => ! $isUser,
        ])>
            <div class="mb-1 flex items-center justify-between gap-3">
                <span class="text-xs font-medium uppercase text-gray-500 dark:text-gray-400">
                    {{ $labels[$author] ?? $author }}
                </span>
                @if (isset($message['timestamp']))
                    <span class="text-xs text-gray-400 dark:text-gray-500">
                        {{ \Illuminate\Support\Carbon::createFromTimestamp($message['timestamp'])->format('M j, Y g:i A') }}
                    </span>
                @endif
            </div>
            <p class="whitespace-pre-wrap text-sm">{{ $message['text'] ?? '' }}</p>
        </div>
    @empty
        <p class="text-sm text-gray-500">No messages in this session.</p>
    @endforelse
</div>
