@extends('layouts.app')

@section('title', 'Verifikasi Pembayaran - INUFA')

@section('header', 'Verifikasi Pembayaran')

@section('content')
<div class="bg-white p-6 rounded-lg shadow-lg">
    <h2 class="text-xl font-bold mb-4">Daftar Pembayaran yang Perlu Diverifikasi</h2>
    
    @if(isset($sewas) && count($sewas) > 0)
    <div class="overflow-x-auto">
        <table class="min-w-full bg-white">
            <thead>
                <tr class="bg-gray-100">
                    <th class="py-3 px-4 text-left">No</th>
                    <th class="py-3 px-4 text-left">Pemesan</th>
                    <th class="py-3 px-4 text-left">Paket</th>
                    <th class="py-3 px-4 text-left">Total Harga</th>
                    <th class="py-3 px-4 text-left">Nominal Pembayaran</th>
                    <th class="py-3 px-4 text-left">Status Pembayaran</th>
                    <th class="py-3 px-4 text-left">Tanggal Pembayaran</th>
                    <th class="py-3 px-4 text-left">Lokasi Acara</th>
                    <th class="py-3 px-4 text-left">Kota Tujuan</th>
                    <th class="py-3 px-4 text-left">Ongkir</th>
                    <th class="py-3 px-4 text-left">Status</th>
                    <th class="py-3 px-4 text-left">Bukti Pembayaran</th>
                    <th class="py-3 px-4 text-left">Jaminan</th>
                    <th class="py-3 px-4 text-left">Catatan</th>
                    <th class="py-3 px-4 text-left">Aksi</th>
                </tr>
            </thead>
            <tbody>
                @foreach($sewas as $index => $sewa)
                <tr class="border-b hover:bg-gray-50">
                    <td class="py-3 px-4">{{ $index + 1 }}</td>
                    <td class="py-3 px-4">
                        {{ $sewa->user->nama }}<br>
                        <span class="text-sm text-gray-500">{{ $sewa->user->email }}</span>
                    </td>
                    <td class="py-3 px-4">{{ $sewa->paket->nama_paket }}</td>
                    <td class="py-3 px-4">Rp {{ number_format($sewa->total_harga, 0, ',', '.') }}</td>
                    <td class="py-3 px-4">
                        @if($sewa->nominal_pembayaran)
                            Rp {{ number_format($sewa->nominal_pembayaran, 0, ',', '.') }}
                        @else
                            <span class="text-gray-500">-</span>
                        @endif
                    </td>
                    <td class="py-3 px-4">
                        @if($sewa->nominal_pembayaran)
                            @if($sewa->nominal_pembayaran >= $sewa->total_harga)
                                <span class="px-2 py-1 bg-green-100 text-green-800 rounded-full text-xs font-semibold">
                                    Lunas
                                </span>
                            @else
                                <span class="px-2 py-1 bg-yellow-100 text-yellow-800 rounded-full text-xs font-semibold">
                                    DP {{ number_format(($sewa->nominal_pembayaran / $sewa->total_harga) * 100, 0) }}%
                                </span>
                            @endif
                        @else
                            <span class="px-2 py-1 bg-red-100 text-red-800 rounded-full text-xs font-semibold">
                                Belum Bayar
                            </span>
                        @endif
                    </td>
                    <td class="py-3 px-4">{{ date('d/m/Y H:i', strtotime($sewa->tanggal_pembayaran)) }}</td>
                    <td class="py-3 px-4">
                        <span class="text-sm">{{ $sewa->lokasi }}</span>
                    </td>
                    <td class="py-3 px-4">
                        @if($sewa->kota)
                            <span class="text-sm font-medium">{{ $sewa->kota->nama_kota }}</span>
                        @else
                            <span class="text-gray-500">-</span>
                        @endif
                    </td>
                    <td class="py-3 px-4">
                        @if($sewa->ongkir)
                            <span class="text-sm">Rp {{ number_format($sewa->ongkir, 0, ',', '.') }}</span>
                        @else
                            <span class="text-gray-500">-</span>
                        @endif
                    </td>
                    <td class="py-3 px-4">
                        <span class="px-2 py-1 rounded-full text-xs font-semibold
                            @if($sewa->status == 'pending') bg-yellow-100 text-yellow-800
                            @elseif($sewa->status == 'dibatalkan') bg-red-100 text-red-800
                            @endif">
                            @if($sewa->status == 'dibatalkan')
                                Dibatalkan oleh Penyewa
                            @else
                                Menunggu Verifikasi
                            @endif
                        </span>
                    </td>
                    <td class="py-3 px-4">
                        <a href="{{ Storage::url($sewa->bukti_pembayaran) }}" target="_blank" 
                           class="text-blue-600 hover:text-blue-800">
                            Lihat Bukti
                        </a>
                    </td>
                    <td class="py-3 px-4">
                        @if($sewa->foto_jaminan)
                            <div class="space-y-1">
                                <p class="text-sm text-gray-600">{{ ucfirst($sewa->jenis_jaminan) }}</p>
                                <a href="{{ Storage::url($sewa->foto_jaminan) }}" target="_blank" 
                                   class="text-blue-600 hover:text-blue-800">
                                    Lihat Jaminan
                                </a>
                            </div>
                        @else
                            <span class="text-gray-400">Belum ada</span>
                        @endif
                    </td>
                    <td class="py-3 px-4">
                        @if($sewa->catatan)
                            <span class="text-sm text-gray-600">{{ $sewa->catatan }}</span>
                        @else
                            <span class="text-gray-400">-</span>
                        @endif
                    </td>
                    <td class="py-3 px-4">
                        @if($sewa->status != 'dibatalkan')
                        <div class="space-y-2">
                            <div class="flex space-x-2">
                                <form action="{{ route('admin.verifikasi.approve', $sewa->id) }}" method="POST" class="inline">
                                    @csrf
                                    <button type="submit" 
                                            class="bg-green-500 text-white px-3 py-1 rounded hover:bg-green-600">
                                        Setujui
                                    </button>
                                </form>
                                <form action="{{ route('admin.verifikasi.reject', $sewa->id) }}" method="POST" class="inline">
                                    @csrf
                                    <button type="submit" 
                                            class="bg-red-500 text-white px-3 py-1 rounded hover:bg-red-600">
                                        Tolak
                                    </button>
                                </form>
                            </div>
                            
                            <!-- Tombol Chat -->
                            <a href="{{ route('chat.show', $sewa->user_id) }}" 
                               class="inline-flex items-center justify-center w-full px-3 py-1 bg-blue-500 text-white rounded hover:bg-blue-600">
                                <svg class="h-4 w-4 mr-1" 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>
                                Chat dengan Penyewa
                            </a>
                        </div>
                        @endif
                    </td>
                </tr>
                @endforeach
            </tbody>
        </table>
    </div>
    @else
    <div class="text-center py-8">
        <p class="text-gray-500">Tidak ada pembayaran yang perlu diverifikasi</p>
    </div>
    @endif
</div>
@endsection 