@extends('layouts.frontend')
@section('title', 'Pesan Saya')
@section('content')
<div class="container py-5">
    <h2 class="mb-4">Pesan Saya</h2>
    <div class="card shadow-sm border-0">
        <div class="list-group list-group-flush">
            @forelse($chatList as $chat)
                <a href="{{ route('pembeli.pesan.show', $chat['lawan_id']) }}" class="list-group-item list-group-item-action py-3 d-flex align-items-center">
                    <img src="{{ asset('template/frontend/img/avatar.jpg') }}" class="rounded-circle me-3" width="50" height="50">
                    <div class="flex-grow-1">
                        <div class="d-flex w-100 justify-content-between">
                            <h5 class="mb-1 text-primary">{{ $chat['nama'] }}</h5>
                            <small class="text-muted">{{ $chat['time'] }}</small>
                        </div>
                        <p class="mb-1 text-muted">{{ Str::limit($chat['last_message'], 50) }}</p>
                    </div>
                    @if($chat['unread'] > 0)
                        <span class="badge bg-danger rounded-pill ms-2">{{ $chat['unread'] }}</span>
                    @endif
                </a>
            @empty
                <div class="text-center py-5">
                    <i class="fa fa-envelope-open fa-3x text-muted mb-3"></i>
                    <p class="text-muted">Belum ada percakapan. Mulai chat dari halaman detail produk.</p>
                    <a href="{{ route('shop') }}" class="btn btn-outline-primary rounded-pill">Lihat Produk</a>
                </div>
            @endforelse
        </div>
    </div>
</div>
@endsection