<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>{{ $title }}</title>

    <style>
        @page {
            margin: 2cm;
        }

        body {
            font-family: Helvetica, Arial, sans-serif;
            font-size: 10pt;
            color: #333;
            line-height: 1.4;
        }

        .header {
            text-align: center;
            margin-bottom: 25px;
            border-bottom: 2px solid #333;
            padding-bottom: 10px;
        }

        .header h1 {
            margin: 0;
            font-size: 18pt;
            text-transform: uppercase;
            font-weight: bold;
        }

        .header h2 {
            margin: 5px 0 0;
            font-size: 14pt;
            font-weight: normal;
        }

        .meta-info {
            margin-bottom: 20px;
        }

        .meta-info table {
            width: 100%;
            border: none;
            font-size: 10pt;
        }

        .meta-info td {
            padding: 3px;
        }

        .report-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 20px;
        }

        .report-table th,
        .report-table td {
            border: 1px solid #ccc;
            padding: 6px;
            vertical-align: top;
        }

        .report-table th {
            background: #f2f2f2;
            font-size: 9pt;
            text-transform: uppercase;
        }

        .report-table tr:nth-child(even) {
            background: #fafafa;
        }

        .w-no {
            width: 4%;
            text-align: center;
        }

        .w-date {
            width: 11%;
        }

        .w-status {
            width: 12%;
        }

        .w-qty {
            width: 8%;
            text-align: center;
        }

        .status-rejected {
            color: #dc2626;
            font-weight: bold;
        }

        .status-approved {
            color: #16a34a;
            font-weight: bold;
        }

        .status-pending {
            color: #d97706;
            font-weight: bold;
        }

        .status-active {
            color: #2563eb;
            font-weight: bold;
        }

        .footer {
            margin-top: 40px;
            text-align: right;
            font-size: 9pt;
        }
    </style>
</head>

<body>

    <div class="header">
        <h1>Sistem Inventaris Sekretariat</h1>
        <h2>{{ $title }}</h2>
    </div>

    <div class="meta-info">
        <table>
            <tr>
                <td width="120"><strong>Periode</strong></td>
                <td>:
                    {{ \Carbon\Carbon::parse($dateFrom)->format('d F Y') }}
                    -
                    {{ \Carbon\Carbon::parse($dateTo)->format('d F Y') }}
                </td>
            </tr>
            <tr>
                <td><strong>Dicetak</strong></td>
                <td>: {{ now()->format('d F Y, H:i') }}</td>
            </tr>
        </table>
    </div>

    <table class="report-table">
        <thead>
            <tr>
                <th class="w-no">No</th>

                @if($reportType === 'room')
                <th>Peminjam</th>
                <th>Divisi</th>
                <th>Ruangan</th>
                <th>Kegiatan</th>
                <th class="w-date">Mulai</th>
                <th class="w-date">Selesai</th>
                <th class="w-status">Status</th>

                @elseif($reportType === 'vehicle')
                <th>Kendaraan</th>
                <th>Peminjam</th>
                <th>Divisi</th>
                <th>Keperluan</th>
                <th>Tujuan</th>
                <th class="w-date">Mulai</th>
                <th class="w-date">Selesai</th>
                <th class="w-status">Status</th>

                @elseif($reportType === 'item_request')
                <th>Peminta</th>
                <th>Divisi</th>
                <th>Barang</th>
                <th class="w-qty">Jumlah</th>
                <th class="w-date">Tgl Pengajuan</th>
                <th class="w-date">Target Realisasi</th>
                <th>Keperluan</th>
                <th>Catatan Admin</th>
                <th class="w-status">Status</th>

                @else
                <th>Peminjam</th>
                <th>Divisi</th>
                <th>Barang</th>
                <th class="w-qty">Jml</th>
                <th class="w-date">Pinjam</th>
                <th class="w-date">Rencana Kembali</th>
                <th class="w-date">Aktual Kembali</th>
                <th class="w-status">Status</th>
                @endif
            </tr>
        </thead>

        <tbody>
            @forelse($data as $item)
            <tr>
                <td style="text-align:center">{{ $loop->iteration }}</td>

                @if($reportType === 'room')
                <td>{{ $item->user->name ?? '-' }}</td>
                <td>{{ $item->user->divisi->nama ?? '-' }}</td>
                <td><strong>{{ $item->room->name ?? '-' }}</strong></td>
                <td>{{ $item->title }}</td>
                <td>{{ $item->start_time->format('d/m/Y H:i') }}</td>
                <td>{{ $item->end_time->format('d/m/Y H:i') }}</td>
                <td>
                    @if($item->status === 'rejected')
                    <span class="status-rejected">Ditolak</span>
                    @elseif($item->status === 'approved')
                    <span class="status-approved">Disetujui</span>
                    @else
                    <span class="status-pending">{{ ucfirst($item->status) }}</span>
                    @endif
                </td>

                @elseif($reportType === 'vehicle')
                <td><strong>{{ $item->vehicle->name ?? '-' }}</strong></td>
                <td>{{ $item->user->name ?? '-' }}</td>
                <td>{{ $item->user->divisi->nama ?? '-' }}</td>
                <td>{{ $item->purpose ?? '-' }}</td>
                <td>{{ $item->destination ?? '-' }}</td>
                <td>{{ $item->start_time->format('d/m/Y H:i') }}</td>
                <td>{{ $item->end_time->format('d/m/Y H:i') }}</td>
                <td>
                    @if($item->status === 'rejected')
                    <span class="status-rejected">Ditolak</span>
                    @elseif($item->status === 'approved')
                    <span class="status-approved">Disetujui</span>
                    @else
                    <span class="status-pending">{{ ucfirst($item->status) }}</span>
                    @endif
                </td>

                @elseif($reportType === 'item_request')
                <td>{{ $item->user->name ?? '-' }}</td>
                <td>{{ $item->user->divisi->nama ?? '-' }}</td>
                <td>{{ $item->item_name_snapshot ?? '-' }}</td>
                <td style="text-align:center">
                    {{ rtrim(rtrim(number_format($item->quantity, 2, '.', ''), '0'), '.') }} {{ $item->unit_snapshot ?? '-' }}
                </td>
                <td>{{ $item->request_date ? \Carbon\Carbon::parse($item->request_date)->format('d/m/Y') : '-' }}</td>
                <td>{{ $item->realization_date ? \Carbon\Carbon::parse($item->realization_date)->format('d/m/Y') : '-' }}</td>
                <td>{{ $item->purpose ?? '-' }}</td>
                <td>{{ $item->admin_note ?? '-' }}</td>
                <td>
                    @if($item->status === 'approved')
                    <span class="status-approved">Baik (sesuai quantity)</span>
                    @elseif($item->status === 'cancelled')
                    <span class="status-rejected">Belum diterima</span>
                    @else
                    <span class="status-pending">Menunggu verifikasi</span>
                    @endif
                </td>

                @else
                <td>{{ $item->user->name ?? '-' }}</td>
                <td>{{ $item->user->divisi->nama ?? '-' }}</td>
                <td>{{ $item->item->nama ?? '-' }}</td>
                <td style="text-align:center">{{ $item->jumlah }}</td>
                <td>{{ \Carbon\Carbon::parse($item->tanggal_pinjam)->format('d/m/Y H:i') }}</td>
                <td>{{ $item->tanggal_kembali ? \Carbon\Carbon::parse($item->tanggal_kembali)->format('d/m/Y') : '-' }}</td>
                <td>{{ $item->actual_return_date ? \Carbon\Carbon::parse($item->actual_return_date)->format('d/m/Y H:i') : '-' }}</td>
                <td>
                    @if($item->status === 'rejected')
                    <span class="status-rejected">Ditolak</span>
                    @elseif($item->actual_return_date)
                    <span class="status-approved">Dikembalikan</span>
                    @else
                    <span class="status-active">Belum Kembali</span>
                    @endif
                </td>
                @endif
            </tr>
            @empty
            <tr>
                <td colspan="10" style="text-align:center;padding:20px">
                    Tidak ada data
                </td>
            </tr>
            @endforelse
        </tbody>
    </table>

    <div class="footer">
        <p>Surabaya, {{ now()->format('d F Y') }}</p>
        <p>Mengetahui,</p>
        <br><br><br>
        <p>( _______________________ )</p>
        <p>Kepala Bagian Umum</p>
    </div>

</body>

</html>
