<?php
require_once __DIR__ . '/../../config/session.php';
requireAdmin();
require_once __DIR__ . '/../../config/config.php';
require_once __DIR__ . '/../../functions/helper.php';

$db = getDB();

$bulan = $_GET['bulan'] ?? '';
$tahun = $_GET['tahun'] ?? '';

$limit = 10;
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
if ($page < 1) $page = 1;
$offset = ($page - 1) * $limit;

// Check if filter is applied
$filter_applied = !empty($bulan) && !empty($tahun);

// ── Filter laporan kunjungan ──────────────────────────────────
$bulan_k = $_GET['bulan_k'] ?? '';
$tahun_k  = $_GET['tahun_k']  ?? '';
$filter_k = !empty($bulan_k) && !empty($tahun_k);

$limit_k = 10;
$page_k  = isset($_GET['page_k']) ? (int)$_GET['page_k'] : 1;
if ($page_k < 1) $page_k = 1;
$offset_k = ($page_k - 1) * $limit_k;

$sqlK = "SELECT kp.tanggal_kunjungan, kp.usia_kehamilan_minggu, kp.tekanan_darah,
                kp.berat_badan, kp.tinggi_fundus, kp.letak_janin, kp.denyut_jantung_janin,
                ih.nama_lengkap, ih.nik, u.nama_lengkap AS nama_bidan
         FROM kunjungan_posyandu kp
         JOIN ibu_hamil ih ON kp.ibu_hamil_id = ih.id
         LEFT JOIN users u ON ih.bidan_id = u.id";
$paramsK = [];
if ($filter_k) {
    $sqlK .= " WHERE MONTH(kp.tanggal_kunjungan) = ? AND YEAR(kp.tanggal_kunjungan) = ?";
    $paramsK = [$bulan_k, $tahun_k];
}
$sqlKCount = "SELECT COUNT(*) FROM kunjungan_posyandu kp
              JOIN ibu_hamil ih ON kp.ibu_hamil_id = ih.id"
    . ($filter_k ? " WHERE MONTH(kp.tanggal_kunjungan) = ? AND YEAR(kp.tanggal_kunjungan) = ?" : "");
$countK = $db->prepare($sqlKCount);
$countK->execute($paramsK);
$total_k = $countK->fetchColumn();
$total_pages_k = ceil($total_k / $limit_k);

$stmtK = $db->prepare($sqlK . " ORDER BY kp.tanggal_kunjungan DESC LIMIT $limit_k OFFSET $offset_k");
$stmtK->execute($paramsK);
$kunjungan_data = $stmtK->fetchAll();
$fmtDec = fn($v) => $v !== null ? rtrim(rtrim(number_format((float)$v, 2, '.', ''), '0'), '.') : '-';

if ($filter_applied) {
    $countStmt = $db->prepare("SELECT COUNT(*) FROM ibu_hamil WHERE MONTH(tanggal_daftar) = ? AND YEAR(tanggal_daftar) = ?");
    $countStmt->execute([$bulan, $tahun]);
    $total_rows = $countStmt->fetchColumn();

    $stmt = $db->prepare("SELECT ih.nik, ih.nama_lengkap, ih.hpl, ih.status, u.nama_lengkap as nama_bidan, ih.hpht FROM ibu_hamil ih LEFT JOIN users u ON ih.bidan_id = u.id WHERE MONTH(ih.tanggal_daftar) = ? AND YEAR(ih.tanggal_daftar) = ? ORDER BY ih.tanggal_daftar DESC LIMIT $limit OFFSET $offset");
    $stmt->execute([$bulan, $tahun]);
} else {
    $total_rows = $db->query("SELECT COUNT(*) FROM ibu_hamil")->fetchColumn();

    $stmt = $db->query("SELECT ih.nik, ih.nama_lengkap, ih.hpl, ih.status, u.nama_lengkap as nama_bidan, ih.hpht FROM ibu_hamil ih LEFT JOIN users u ON ih.bidan_id = u.id ORDER BY ih.tanggal_daftar DESC LIMIT $limit OFFSET $offset");
}
$laporan_data = $stmt->fetchAll();
$total_pages = ceil($total_rows / $limit);

// Statistik singkat
$total_baru = count($laporan_data);

?>
<?php require_once '../../includes/header_admin.php'; ?>

<div class="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-6">
    <div>
        <h1 class="text-2xl font-bold text-gray-800">Laporan Data Ibu Hamil</h1>
        <p class="text-gray-500 text-sm mt-1">Laporan pendaftaran ibu hamil baru per bulan.</p>
    </div>
</div>

<div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden mb-6">
    <div class="px-4 md:px-6 py-4 border-b border-gray-100 flex items-center gap-2 bg-gray-50/50">
        <i class="fas fa-filter text-gray-400"></i>
        <h3 class="font-bold text-gray-800 text-sm">Filter Laporan</h3>
    </div>
    <div class="p-4 md:p-6">
        <form method="GET" class="flex flex-col gap-4">
            <div class="flex flex-col sm:flex-row gap-4">
                <div class="w-full sm:w-1/3">
                    <label class="block text-xs font-bold text-gray-500 uppercase tracking-wider mb-2">Bulan</label>
                    <select name="bulan" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-primary text-sm bg-white">
                        <option value="" <?= empty($bulan) ? 'selected' : '' ?>>Semua</option>
                        <?php for($m=1; $m<=12; ++$m): ?>
                            <option value="<?= sprintf("%02d", $m) ?>" <?= $bulan == sprintf("%02d", $m) ? 'selected' : '' ?>><?= formatBulan($m) ?></option>
                        <?php endfor; ?>
                    </select>
                </div>
                <div class="w-full sm:w-1/4">
                    <label class="block text-xs font-bold text-gray-500 uppercase tracking-wider mb-2">Tahun</label>
                    <select name="tahun" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-primary text-sm bg-white">
                        <option value="" <?= empty($tahun) ? 'selected' : '' ?>>Semua</option>
                        <?php $year_now = date('Y'); for($y=$year_now-2; $y<=$year_now+2; $y++): ?>
                            <option value="<?= $y ?>" <?= $tahun == $y ? 'selected' : '' ?>><?= $y ?></option>
                        <?php endfor; ?>
                    </select>
                </div>
            </div>
            <div class="flex flex-col sm:flex-row gap-2">
                <button type="submit" class="px-4 py-2 bg-gray-800 hover:bg-gray-900 text-white font-medium rounded-lg transition-colors text-sm flex items-center justify-center">
                    <i class="fas fa-search mr-2"></i> Tampilkan
                </button>
                <a href="cetak_excel?bulan=<?= $bulan ?>&tahun=<?= $tahun ?>" target="_blank" class="px-4 py-2 bg-green-600 hover:bg-green-700 text-white font-medium rounded-lg transition-colors text-sm flex items-center justify-center">
                    <i class="fas fa-file-excel mr-2"></i> Export
                </a>
                <a href="cetak_pdf?bulan=<?= $bulan ?>&tahun=<?= $tahun ?>" target="_blank" class="px-4 py-2 bg-red-500 hover:bg-red-600 text-white font-medium rounded-lg transition-colors text-sm flex items-center justify-center">
                    <i class="fas fa-file-pdf mr-2"></i> Cetak PDF
                </a>
            </div>
        </form>
    </div>
</div>

<div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden mb-8">
    <div class="px-6 py-4 border-b border-gray-100 bg-gray-50/50">
        <h3 class="font-bold text-gray-800">Preview Data Laporan</h3>
    </div>

    <!-- Desktop Table -->
    <div class="hidden md:block overflow-x-auto">
        <table class="w-full text-sm text-left whitespace-nowrap">
            <thead class="text-xs text-gray-500 uppercase bg-gray-50 border-b border-gray-100">
                <tr>
                    <th class="px-6 py-4 font-semibold">No</th>
                    <th class="px-6 py-4 font-semibold">NIK</th>
                    <th class="px-6 py-4 font-semibold">Nama Ibu</th>
                    <th class="px-6 py-4 font-semibold text-center">Usia Kehamilan</th>
                    <th class="px-6 py-4 font-semibold text-center">HPL</th>
                    <th class="px-6 py-4 font-semibold text-center">Perkiraan</th>
                    <th class="px-6 py-4 font-semibold">Bidan PJ</th>
                    <th class="px-6 py-4 font-semibold text-center">Status</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
                <?php if (count($laporan_data) > 0): ?>
                    <?php $no = 1; foreach ($laporan_data as $row): ?>
                        <?php 
                            $diff = (new DateTime($row['hpht']))->diff(new DateTime())->days;
                            $minggu = intdiv($diff, 7);
                            $hpl_date = new DateTime($row['hpl']);
                            $today = new DateTime();
                            $is_overdue = $hpl_date < $today;
                            $days_to_hpl = $today->diff($hpl_date)->days;
                            
                            $status_color = match($row['status']) {
                                'Aktif' => 'bg-sky-100 text-sky-800 border-sky-200',
                                'Melahirkan' => 'bg-blue-100 text-blue-800 border-blue-200',
                                'Keguguran' => 'bg-red-100 text-red-800 border-red-200',
                                'Pindah' => 'bg-gray-100 text-gray-800 border-gray-200',
                                default => 'bg-gray-100 text-gray-800 border-gray-200'
                            };
                        ?>
                        <tr class="hover:bg-gray-50 transition-colors">
                            <td class="px-6 py-4 text-gray-500"><?= $no++ ?></td>
                            <td class="px-6 py-4 font-mono text-xs text-gray-500"><?= escape($row['nik']) ?></td>
                            <td class="px-6 py-4 font-bold text-gray-900"><?= escape($row['nama_lengkap']) ?></td>
                            <td class="px-6 py-4 text-center">
                                <span class="font-medium text-gray-900"><?= $minggu ?></span> <span class="text-xs text-gray-500">Minggu</span>
                            </td>
                            <td class="px-6 py-4 text-center">
                                <div class="font-medium <?= $is_overdue ? 'text-red-500' : 'text-primary' ?>"><?= date('d-m-Y', strtotime($row['hpl'])) ?></div>
                            </td>
                            <td class="px-6 py-4 text-center">
                                <?php if($is_overdue): ?>
                                    <span class="text-xs font-bold text-red-500">Melewati HPL</span>
                                <?php else: ?>
                                    <span class="font-semibold text-gray-900"><?= $days_to_hpl ?></span> <span class="text-xs text-gray-500">hari lagi</span>
                                <?php endif; ?>
                            </td>
                            <td class="px-6 py-4 text-gray-700"><?= escape($row['nama_bidan']) ?></td>
                            <td class="px-6 py-4 text-center">
                                <span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold border uppercase tracking-wider <?= $status_color ?>">
                                    <?= escape($row['status']) ?>
                                </span>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr>
                        <td colspan="8" class="px-6 py-12 text-center text-gray-500">
                            <i class="fas fa-folder-open text-4xl mb-3 text-gray-300 block"></i>
                            Tidak ada data pendaftaran di bulan ini.
                        </td>
                    </tr>
                <?php endif; ?>
            </tbody>
        </table>
    </div>

    <!-- Mobile Cards -->
    <div class="md:hidden divide-y divide-gray-100">
        <?php if (count($laporan_data) > 0): ?>
            <?php $no = 1; foreach ($laporan_data as $row): ?>
                <?php 
                    $diff = (new DateTime($row['hpht']))->diff(new DateTime())->days;
                    $minggu = intdiv($diff, 7);
                    $hpl_date = new DateTime($row['hpl']);
                    $today = new DateTime();
                    $is_overdue = $hpl_date < $today;
                    $days_to_hpl = $today->diff($hpl_date)->days;
                    
                    $status_color = match($row['status']) {
                        'Aktif' => 'bg-sky-100 text-sky-800 border-sky-200',
                        'Melahirkan' => 'bg-blue-100 text-blue-800 border-blue-200',
                        'Keguguran' => 'bg-red-100 text-red-800 border-red-200',
                        'Pindah' => 'bg-gray-100 text-gray-800 border-gray-200',
                        default => 'bg-gray-100 text-gray-800 border-gray-200'
                    };
                ?>
                <div class="p-4 hover:bg-gray-50 transition-colors">
                    <div class="flex items-start justify-between mb-3">
                        <div>
                            <div class="font-bold text-gray-900"><?= escape($row['nama_lengkap']) ?></div>
                            <div class="text-xs text-gray-500 font-mono mt-0.5"><?= escape($row['nik']) ?></div>
                        </div>
                        <span class="inline-flex items-center px-2 py-0.5 rounded text-[10px] font-bold border uppercase tracking-wider <?= $status_color ?>">
                            <?= escape($row['status']) ?>
                        </span>
                    </div>
                    <div class="grid grid-cols-3 gap-2 text-center">
                        <div class="bg-gray-50 rounded-lg p-2">
                            <p class="text-[10px] text-gray-500 uppercase font-semibold">Usia</p>
                            <p class="text-sm font-bold text-gray-900"><?= $minggu ?> <span class="text-xs font-normal text-gray-500">mgg</span></p>
                        </div>
                        <div class="bg-gray-50 rounded-lg p-2">
                            <p class="text-[10px] text-gray-500 uppercase font-semibold">HPL</p>
                            <p class="text-xs font-bold <?= $is_overdue ? 'text-red-500' : 'text-primary' ?>"><?= date('d M Y', strtotime($row['hpl'])) ?></p>
                        </div>
                        <div class="bg-gray-50 rounded-lg p-2">
                            <p class="text-[10px] text-gray-500 uppercase font-semibold">Perkiraan</p>
                            <?php if($is_overdue): ?>
                                <p class="text-xs font-bold text-red-500">Lewati HPL</p>
                            <?php else: ?>
                                <p class="text-sm font-bold text-gray-900"><?= $days_to_hpl ?> <span class="text-xs font-normal text-gray-500">hari</span></p>
                            <?php endif; ?>
                        </div>
                    </div>
                    <div class="mt-2 text-xs text-gray-500"><i class="fas fa-user-md mr-1"></i> Bidan: <?= escape($row['nama_bidan']) ?: '-' ?></div>
                </div>
            <?php endforeach; ?>
        <?php else: ?>
            <div class="px-6 py-12 text-center text-gray-500">
                <i class="fas fa-folder-open text-4xl mb-3 text-gray-300 block"></i>
                Tidak ada data pendaftaran di bulan ini.
            </div>
        <?php endif; ?>
    </div>

    <?= renderPagination($total_pages, $page, './', $_GET) ?>
</div>

<!-- ══════════════════════════════════════════════════════════ -->
<!-- SECTION: LAPORAN KUNJUNGAN POSYANDU                      -->
<!-- ══════════════════════════════════════════════════════════ -->

<div class="flex flex-col md:flex-row md:items-center justify-between gap-4 mb-6 mt-4">
    <div>
        <h1 class="text-2xl font-bold text-gray-800">Laporan Kunjungan Posyandu</h1>
        <p class="text-gray-500 text-sm mt-1">Data rekam medis kunjungan seluruh ibu hamil.</p>
    </div>
</div>

<div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden mb-6">
    <div class="px-4 md:px-6 py-4 border-b border-gray-100 flex items-center gap-2 bg-gray-50/50">
        <i class="fas fa-filter text-gray-400"></i>
        <h3 class="font-bold text-gray-800 text-sm">Filter Laporan Kunjungan</h3>
    </div>
    <div class="p-4 md:p-6">
        <form method="GET" class="flex flex-col gap-4">
            <?php foreach (['bulan','tahun'] as $k): ?>
                <input type="hidden" name="<?= $k ?>" value="<?= escape($$k) ?>">
            <?php endforeach; ?>
            <div class="flex flex-col sm:flex-row gap-4">
                <div class="w-full sm:w-1/3">
                    <label class="block text-xs font-bold text-gray-500 uppercase tracking-wider mb-2">Bulan</label>
                    <select name="bulan_k" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-primary text-sm bg-white">
                        <option value="" <?= empty($bulan_k) ? 'selected' : '' ?>>Semua</option>
                        <?php for($m=1; $m<=12; ++$m): ?>
                            <option value="<?= sprintf('%02d',$m) ?>" <?= $bulan_k == sprintf('%02d',$m) ? 'selected' : '' ?>><?= formatBulan($m) ?></option>
                        <?php endfor; ?>
                    </select>
                </div>
                <div class="w-full sm:w-1/4">
                    <label class="block text-xs font-bold text-gray-500 uppercase tracking-wider mb-2">Tahun</label>
                    <select name="tahun_k" class="w-full px-3 py-2 border border-gray-300 rounded-lg focus:ring-2 focus:ring-primary focus:border-primary text-sm bg-white">
                        <option value="" <?= empty($tahun_k) ? 'selected' : '' ?>>Semua</option>
                        <?php $yn = date('Y'); for($y=$yn-2; $y<=$yn+2; $y++): ?>
                            <option value="<?= $y ?>" <?= $tahun_k == $y ? 'selected' : '' ?>><?= $y ?></option>
                        <?php endfor; ?>
                    </select>
                </div>
            </div>
            <div class="flex flex-col sm:flex-row gap-2">
                <button type="submit" class="px-4 py-2 bg-gray-800 hover:bg-gray-900 text-white font-medium rounded-lg transition-colors text-sm flex items-center justify-center">
                    <i class="fas fa-search mr-2"></i> Tampilkan
                </button>
                <a href="cetak_excel_kunjungan?bulan=<?= $bulan_k ?>&tahun=<?= $tahun_k ?>" target="_blank"
                   class="px-4 py-2 bg-green-600 hover:bg-green-700 text-white font-medium rounded-lg transition-colors text-sm flex items-center justify-center">
                    <i class="fas fa-file-excel mr-2"></i> Export Excel
                </a>
                <a href="cetak_pdf_kunjungan?bulan=<?= $bulan_k ?>&tahun=<?= $tahun_k ?>" target="_blank"
                   class="px-4 py-2 bg-red-500 hover:bg-red-600 text-white font-medium rounded-lg transition-colors text-sm flex items-center justify-center">
                    <i class="fas fa-file-pdf mr-2"></i> Cetak PDF
                </a>
            </div>
        </form>
    </div>
</div>

<div class="bg-white rounded-2xl shadow-sm border border-gray-100 overflow-hidden mb-8">
    <div class="px-6 py-4 border-b border-gray-100 bg-gray-50/50 flex items-center justify-between">
        <h3 class="font-bold text-gray-800">Preview Data Kunjungan</h3>
        <span class="text-xs text-gray-500"><?= $total_k ?> kunjungan</span>
    </div>

    <!-- Desktop Table -->
    <div class="hidden md:block overflow-x-auto">
        <table class="w-full text-sm text-left whitespace-nowrap">
            <thead class="text-xs text-gray-500 uppercase bg-gray-50 border-b border-gray-100">
                <tr>
                    <th class="px-4 py-4 font-semibold">No</th>
                    <th class="px-4 py-4 font-semibold">Tanggal</th>
                    <th class="px-4 py-4 font-semibold">Nama / NIK</th>
                    <th class="px-4 py-4 font-semibold text-center">Usia (mgg)</th>
                    <th class="px-4 py-4 font-semibold text-center">Tek. Darah</th>
                    <th class="px-4 py-4 font-semibold text-center">Berat (kg)</th>
                    <th class="px-4 py-4 font-semibold text-center">TFU (cm)</th>
                    <th class="px-4 py-4 font-semibold text-center">Letak Janin</th>
                    <th class="px-4 py-4 font-semibold text-center">DJJ</th>
                    <th class="px-4 py-4 font-semibold">Bidan PJ</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
            <?php if (!empty($kunjungan_data)): ?>
                <?php $no = ($page_k - 1) * $limit_k + 1; foreach ($kunjungan_data as $kj): ?>
                    <tr class="hover:bg-gray-50 transition-colors">
                        <td class="px-4 py-3 text-gray-500"><?= $no++ ?></td>
                        <td class="px-4 py-3 font-medium text-gray-800"><?= formatDate($kj['tanggal_kunjungan']) ?></td>
                        <td class="px-4 py-3">
                            <div class="font-bold text-gray-900"><?= escape($kj['nama_lengkap']) ?></div>
                            <div class="text-xs text-gray-500 mt-0.5"><?= escape($kj['nik']) ?></div>
                        </td>
                        <td class="px-4 py-3 text-center text-gray-700"><?= $kj['usia_kehamilan_minggu'] !== null ? escape($kj['usia_kehamilan_minggu']) : '-' ?></td>
                        <td class="px-4 py-3 text-center text-gray-700"><?= $kj['tekanan_darah'] ? escape($kj['tekanan_darah']) : '-' ?></td>
                        <td class="px-4 py-3 text-center text-gray-700"><?= $fmtDec($kj['berat_badan']) ?></td>
                        <td class="px-4 py-3 text-center text-gray-700"><?= $fmtDec($kj['tinggi_fundus']) ?></td>
                        <td class="px-4 py-3 text-center text-gray-700"><?= $kj['letak_janin'] ? escape($kj['letak_janin']) : '-' ?></td>
                        <td class="px-4 py-3 text-center text-gray-700"><?= $kj['denyut_jantung_janin'] !== null ? escape($kj['denyut_jantung_janin']) : '-' ?></td>
                        <td class="px-4 py-3 text-gray-700"><?= escape($kj['nama_bidan'] ?? '-') ?></td>
                    </tr>
                <?php endforeach; ?>
            <?php else: ?>
                <tr>
                    <td colspan="10" class="px-6 py-12 text-center text-gray-500">
                        <i class="fas fa-folder-open text-4xl mb-3 text-gray-300 block"></i>
                        Tidak ada data kunjungan<?= $filter_k ? ' pada bulan ini.' : '.' ?>
                    </td>
                </tr>
            <?php endif; ?>
            </tbody>
        </table>
    </div>

    <!-- Mobile Cards -->
    <div class="md:hidden divide-y divide-gray-100">
        <?php if (!empty($kunjungan_data)): ?>
            <?php foreach ($kunjungan_data as $kj): ?>
                <div class="p-4 hover:bg-gray-50 transition-colors">
                    <div class="flex items-start justify-between mb-3">
                        <div>
                            <div class="font-bold text-gray-900"><?= escape($kj['nama_lengkap']) ?></div>
                            <div class="text-xs text-gray-500 font-mono mt-0.5"><?= escape($kj['nik']) ?></div>
                        </div>
                        <span class="text-xs font-medium text-primary bg-primary/10 px-2 py-0.5 rounded-full"><?= formatDate($kj['tanggal_kunjungan']) ?></span>
                    </div>
                    <div class="grid grid-cols-3 gap-2 text-center">
                        <div class="bg-red-50 rounded-lg p-2">
                            <p class="text-[10px] text-red-400 uppercase font-semibold">Tek. Darah</p>
                            <p class="text-xs font-bold text-gray-900"><?= $kj['tekanan_darah'] ? escape($kj['tekanan_darah']) : '-' ?></p>
                        </div>
                        <div class="bg-blue-50 rounded-lg p-2">
                            <p class="text-[10px] text-blue-400 uppercase font-semibold">Berat</p>
                            <p class="text-xs font-bold text-gray-900"><?= $fmtDec($kj['berat_badan']) ?> kg</p>
                        </div>
                        <div class="bg-purple-50 rounded-lg p-2">
                            <p class="text-[10px] text-purple-400 uppercase font-semibold">Usia</p>
                            <p class="text-xs font-bold text-gray-900"><?= $kj['usia_kehamilan_minggu'] !== null ? escape($kj['usia_kehamilan_minggu']).' mgg' : '-' ?></p>
                        </div>
                    </div>
                    <div class="mt-2 text-xs text-gray-500"><i class="fas fa-user-md mr-1"></i> Bidan: <?= escape($kj['nama_bidan'] ?? '-') ?></div>
                </div>
            <?php endforeach; ?>
        <?php else: ?>
            <div class="px-6 py-12 text-center text-gray-500">
                <i class="fas fa-folder-open text-4xl mb-3 text-gray-300 block"></i>
                Tidak ada data kunjungan.
            </div>
        <?php endif; ?>
    </div>

    <?= renderPagination($total_pages_k, $page_k, './', array_merge($_GET, ['page_k' => null])) ?>
</div>

<?php require_once '../../includes/footer_admin.php'; ?>
