<?= $this->extend('v_template/layout') ?>
<?= $this->section('content') ?>

<div class="row mb-4 align-items-center">
    <div class="col-md-8">
        <h4 class="fw-bold text-success"><i class="fa-solid fa-clipboard-list me-2"></i> Rekap Laporan Patroli</h4>
        <p class="text-muted mb-0">Pantauan kondisi lapangan real-time dari Polhut dan Penyuluh.</p>
    </div>
</div>

<div class="card shadow-sm border-0">
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover align-middle mb-0">
                <thead class="table-light text-muted">
                    <tr>
                        <th class="ps-4">Waktu Laporan</th>
                        <th>Petugas</th>
                        <th>Lokasi / Blok</th>
                        <th style="min-width: 250px;">Keterangan Temuan</th>
                        <th class="text-center">Foto Bukti</th>
                        <th class="text-center pe-4">Aksi / Kontak</th>
                    </tr>
                </thead>
                <tbody>
                    <?php if(empty($laporan)) : ?>
                    <tr>
                        <td colspan="6" class="text-center py-5 text-muted">
                            <i class="fa-solid fa-folder-open fa-3x mb-3 text-light"></i>
                            <p>Belum ada laporan patroli yang masuk dari lapangan.</p>
                        </td>
                    </tr>
                    <?php else : ?>
                        <?php foreach($laporan as $row) : ?>
                        <tr>
                            <td class="ps-4 small text-muted">
                                <strong><?= date('d M Y', strtotime($row['waktu_input'])) ?></strong><br>
                                Pukul <?= date('H:i', strtotime($row['waktu_input'])) ?> WIB
                            </td>
                            <td class="fw-bold text-dark">
                                <i class="fa-solid fa-user-shield text-secondary me-1"></i> <?= $row['nama_petugas'] ?>
                            </td>
                            <td><span class="badge bg-warning text-dark border"><?= $row['lokasi_blok'] ?></span></td>
                            <td class="small"><?= $row['temuan'] ?></td>
                            
                            <td class="text-center">
                                <?php if(!empty($row['foto_bukti'])): ?>
                                    <a href="<?= base_url('uploads/patroli/' . $row['foto_bukti']) ?>" target="_blank" class="btn btn-sm btn-outline-info rounded-pill">
                                        <i class="fa-solid fa-image me-1"></i> Lihat
                                    </a>
                                <?php else: ?>
                                    <span class="text-muted small">Tanpa Foto</span>
                                <?php endif; ?>
                            </td>
                            
                            <td class="text-center pe-4">
                                <?php if(!empty($row['no_hp'])): ?>
                                    <a href="https://wa.me/<?= preg_replace('/[^0-9]/', '', $row['no_hp']) ?>" target="_blank" class="btn btn-sm btn-success rounded-pill shadow-sm" title="Chat Petugas via WhatsApp">
                                        <i class="fa-brands fa-whatsapp me-1"></i> Hubungi
                                    </a>
                                <?php else: ?>
                                    <span class="badge bg-light text-muted border" title="Nomor HP belum diisi di Data Pegawai">No HP Kosong</span>
                                <?php endif; ?>
                            </td>
                        </tr>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>

<?= $this->endSection() ?>