<?php
require_once '../config/koneksi.php';

$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;

if ($id <= 0) {
    die('ID siswa tidak valid');
}

$qSiswa = $conn->query("SELECT * FROM siswa WHERE id = $id LIMIT 1");

if (!$qSiswa || $qSiswa->num_rows == 0) {
    die('Data siswa tidak ditemukan');
}

$s = $qSiswa->fetch_assoc();

$qProfil = $conn->query("SELECT * FROM profil_sekolah LIMIT 1");
$p = $qProfil ? $qProfil->fetch_assoc() : [];

if (!function_exists('e')) {
    function e($value)
    {
        return htmlspecialchars((string)$value, ENT_QUOTES, 'UTF-8');
    }
}
?>

<!doctype html>
<html lang="id">

<head>
    <meta charset="utf-8">
    <title>Cetak Kartu Ujian</title>

    <style>
        @page {
            size: A4 landscape;
            margin: 10mm;
        }

        body {
            margin: 0;
            padding: 20px;
            background: #f1f5f9;
            font-family: Arial, sans-serif;
        }

        .no-print {
            margin-bottom: 20px;
        }

        .btn {
            display: inline-block;
            padding: 10px 16px;
            border-radius: 8px;
            text-decoration: none;
            border: none;
            cursor: pointer;
            font-weight: bold;
            font-size: 14px;
        }

        .btn-gray {
            background: #475569;
            color: white;
        }

        .btn-green {
            background: #16a34a;
            color: white;
        }

        .single-card-page {
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: flex-start;
        }

        @media print {
            .no-print {
                display: none !important;
            }

            body {
                background: white;
                padding: 0;
                margin: 0;
                -webkit-print-color-adjust: exact;
                print-color-adjust: exact;
            }

            .single-card-page {
                margin-top: 0;
            }
        }
    </style>
</head>

<body>

    <div class="no-print">
        <a href="../admin/siswa.php" class="btn btn-gray">← Kembali</a>
        <button onclick="window.print()" class="btn btn-green">🖨 Cetak</button>
    </div>

    <div class="single-card-page">
        <?php include 'template_kartu.php'; ?>
    </div>

</body>

</html>