<!DOCTYPE html>
<html>
<head>
    <title>Laporan Pendapatan Tiket Rinci</title>
    <style>
        body { font-family: sans-serif; color: #333; line-height: 1.4; }
        .header { text-align: center; margin-bottom: 20px; border-bottom: 2px solid #000; padding-bottom: 10px; }
        .info-periode { font-size: 13px; margin-bottom: 15px; font-weight: bold; }
        table { width: 100%; border-collapse: collapse; margin-top: 10px; }
        th, td { border: 1px solid #999; padding: 8px; text-align: center; font-size: 11px; }
        th { background-color: #f2f2f2; text-transform: uppercase; }
        .text-left { text-align: left; }
        .total-row { font-weight: bold; background-color: #eee; }
        .footer { margin-top: 40px; text-align: right; font-size: 12px; padding-right: 20px; }
        .stamp { margin-top: 50px; }
    </style>
</head>
<body onload="window.print()">
    <div class="header">
        <h2 style="margin-bottom: 5px;">LAPORAN RINCIAN PENDAPATAN TIKET</h2>
        <h3 style="margin-top: 0; font-weight: normal;">Sistem Manajemen Pendakian Gunung Agung</h3>
        <p style="font-size: 11px;">Dicetak pada: {{ date('d/m/Y H:i') }} WITA</p>
    </div>

    <div class="info-periode">
        PERIODE LAPORAN: 
        @if(isset($start) && isset($end))
            {{ \Carbon\Carbon::parse($start)->format('d F Y') }} s/d {{ \Carbon\Carbon::parse($end)->format('d F Y') }}
        @else
            Semua Data
        @endif
    </div>

    <table>
        <thead>
            <tr>
                <th width="30">No</th>
                <th width="120">Waktu Transaksi</th>
                <th class="text-left">Nama Pendaki</th>
                <th width="100">Kategori</th>
                <th width="130">Harga Tiket</th>
            </tr>
        </thead>
        <tbody>
            @php $totalRecord = 0; @endphp
            @forelse($climbings as $i => $item)
            <tr>
                <td>{{ $i + 1 }}</td>
                <td>{{ $item->created_at->format('d/m/Y H:i') }}</td>
                <td class="text-left">{{ $item->name }}</td>
                <td>
                    {{ strtolower($item->ticket->name ?? '') == 'mancanegara' ? '🌍 WNA' : '🇮🇩 WNI' }}
                </td>
                <td>Rp {{ number_format($item->ticket->price ?? 0, 0, ',', '.') }}</td>
            </tr>
            @php $totalRecord++; @endphp
            @empty
            <tr>
                <td colspan="5">Tidak ada data ditemukan pada rentang tanggal ini.</td>
            </tr>
            @endforelse
            
            <tr class="total-row">
                <td colspan="4" style="text-align: right; padding-right: 15px;">GRAND TOTAL PENDAPATAN ({{ $totalRecord }} Transaksi)</td>
                <td>Rp {{ number_format($totalIncomeAll, 0, ',', '.') }}</td>
            </tr>
        </tbody>
    </table>

    <div class="footer">
        <p>Karangasem, {{ date('d F Y') }}</p>
        <p>Mengetahui,</p>
        <div class="stamp">
            <p><strong>Admin Sistem Manajemen</strong></p>
        </div>
    </div>
</body>
</html>