<!DOCTYPE html>
<html lang="id">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Cetak Riwayat Pengiriman WhatsApp</title>
    <!-- Theme style -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/admin-lte@3.2/dist/css/adminlte.min.css">
    <style>
        body { background: #fff; padding: 20px; font-size: 14px; }
        .text-center { text-align: center; }
        .font-weight-bold { font-weight: bold; }
        .mb-4 { margin-bottom: 1.5rem; }
        table { width: 100%; border-collapse: collapse; margin-top: 10px; }
        th, td { border: 1px solid #000; padding: 5px; }
        th { background-color: #f4f6f9; }
        @media print {
            .no-print { display: none; }
        }
    </style>
</head>
<body onload="window.print()">
    <div class="no-print mb-4">
        <button onclick="window.print()" class="btn btn-primary">Cetak</button>
        <button onclick="window.close()" class="btn btn-default">Tutup</button>
    </div>

    <div class="text-center mb-4">
        <h4 class="font-weight-bold">YPKK KERTAS LECES</h4>
        <h5>RIWAYAT PENGIRIMAN WHATSAPP</h5>
        <p>Tanggal Cetak: {{ date('d-m-Y H:i') }}</p>
    </div>

    <table>
        <thead>
            <tr>
                <th>No</th>
                <th>Tanggal</th>
                <th>Nama Siswa</th>
                <th>Nomor WhatsApp</th>
                <th>Jenis Pesan</th>
                <th>Dikirim Oleh</th>
                <th>Status</th>
                <th>Keterangan</th>
            </tr>
        </thead>
        <tbody>
            @forelse($riwayats as $index => $riwayat)
                <tr>
                    <td class="text-center">{{ $index + 1 }}</td>
                    <td>{{ $riwayat->created_at->format('d-m-Y H:i') }}</td>
                    <td>{{ $riwayat->nama_siswa ?? '-' }}</td>
                    <td>{{ $riwayat->no_wa }}</td>
                    <td>{{ $riwayat->jenis_pesan }}</td>
                    <td>{{ $riwayat->dikirimOleh->name ?? '-' }}</td>
                    <td class="text-center">
                        @if($riwayat->status == 'berhasil')
                            Berhasil
                        @else
                            Gagal
                        @endif
                    </td>
                    <td>{{ $riwayat->keterangan ?? '-' }}</td>
                </tr>
            @empty
                <tr>
                    <td colspan="8" class="text-center">Tidak ada data riwayat pengiriman WhatsApp.</td>
                </tr>
            @endforelse
        </tbody>
    </table>
</body>
</html>
