@extends('layouts.app')

@section('title', 'Daftar Chat - INUFA')
@section('header', 'Daftar Chat')

@section('content')
<div class="container mx-auto px-4 py-6">
    <div class="bg-white rounded-lg shadow-lg p-6">
        <h2 class="text-xl font-bold mb-6">Daftar Percakapan</h2>

        @if($sewas->count() > 0)
            <div class="space-y-4">
                @foreach($sewas as $sewa)
                    <a href="{{ route('chat.index', $sewa->id) }}" 
                       class="block p-4 bg-gray-50 rounded-lg hover:bg-gray-100 transition-colors duration-200">
                        <div class="flex justify-between items-start">
                            <div>
                                <h3 class="font-semibold text-gray-900">Penyewaan #{{ $sewa->id }}</h3>
                                <p class="text-sm text-gray-600">Paket: {{ $sewa->paket->nama_paket }}</p>
                                <p class="text-sm text-gray-600">
                                    {{ $sewa->user->nama }} • {{ $sewa->created_at->format('d M Y H:i') }}
                                </p>
                            </div>
                            @php
                                $unreadCount = $sewa->chats()
                                    ->where('sender_id', '!=', auth()->id())
                                    ->where('is_read', false)
                                    ->count();
                            @endphp
                            @if($unreadCount > 0)
                                <span class="inline-flex items-center justify-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-red-100 text-red-800">
                                    {{ $unreadCount }} pesan baru
                                </span>
                            @endif
                        </div>
                        <div class="mt-2">
                            <p class="text-sm text-gray-600 line-clamp-1">
                                {{ $sewa->chats->last()->message }}
                            </p>
                        </div>
                    </a>
                @endforeach
            </div>
        @else
            <div class="text-center py-12">
                <svg class="mx-auto h-12 w-12 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 12h.01M12 12h.01M16 12h.01M21 12c0 4.418-4.03 8-9 8a9.863 9.863 0 01-4.255-.949L3 20l1.395-3.72C3.512 15.042 3 13.574 3 12c0-4.418 4.03-8 9-8s9 3.582 9 8z" />
                </svg>
                <h3 class="mt-2 text-sm font-medium text-gray-900">Belum ada percakapan</h3>
                <p class="mt-1 text-sm text-gray-500">Mulai percakapan baru dengan mengklik tombol chat di halaman detail sewa.</p>
            </div>
        @endif
    </div>
</div>
@endsection 