<?php
require_once __DIR__.'/../includes/db.php';

$kode = $_GET['kode'] ?? '';

if(!$kode){
  die('Kode verifikasi tidak ditemukan');
}

$q = $mysqli->prepare("
  SELECT *
  FROM surat_undangan
  WHERE qr_kode=?
");
$q->bind_param("s",$kode);
$q->execute();
$data = $q->get_result()->fetch_assoc();

if(!$data){
  die('<h2 style="color:red;text-align:center;margin-top:50px;">❌ QR CODE TIDAK VALID</h2>');
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Verifikasi Surat Undangan</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body{margin:0;font-family:system-ui;background:#f2f5f9}
.container{max-width:520px;margin:40px auto;background:#fff;border-radius:14px;box-shadow:0 10px 30px rgba(0,0,0,.08);overflow:hidden}
.header{background:linear-gradient(135deg,#0f766e,#0d9488);color:#fff;padding:22px;text-align:center}
.content{padding:22px}
.status{background:#ecfeff;border:1px solid #67e8f9;color:#065f46;padding:14px;border-radius:10px;text-align:center;font-weight:600;margin-bottom:18px}
.data{width:100%;font-size:14px}
.data td{padding:8px 0}
.data td:first-child{width:45%;color:#555}
.badge{display:inline-block;padding:6px 14px;border-radius:999px;background:#dcfce7;color:#166534;font-size:12px;font-weight:600}
.btn-preview{display:inline-block;margin-top:20px;padding:10px 18px;background:#0d9488;color:#fff;text-decoration:none;border-radius:8px;font-weight:600}
</style>
</head>
<body>

<div class="container">

<div class="header">
<h2>VERIFIKASI DOKUMEN</h2>
<p>Surat Undangan - Desa Mambu</p>
</div>

<div class="content">

<div class="status">
✅ DOKUMEN INI SAH & TERVERIFIKASI
</div>

<table class="data">
<tr><td>Nomor Surat</td><td>: <b><?= htmlspecialchars($data['nomor_surat']); ?></b></td></tr>
<tr><td>Perihal</td><td>: <?= htmlspecialchars($data['perihal']); ?></td></tr>
<tr><td>Hari / Tanggal</td><td>: <?= htmlspecialchars($data['hari_tanggal']); ?></td></tr>
<tr><td>Tempat</td><td>: <?= htmlspecialchars($data['tempat']); ?></td></tr>
</table>

<hr>

<table class="data">
<tr><td>Pejabat Penandatangan</td><td>: <b>Hayamuddin</b></td></tr>
<tr><td>Jabatan</td><td>: Kepala Desa Mambu</td></tr>
<tr>
<td>Waktu Penandatanganan</td>
<td>: <?= date('d-m-Y H:i:s', strtotime($data['waktu_ttd'])); ?> WITA</td>
</tr>
<tr><td>Status</td><td>: <span class="badge">Tanda Tangan Elektronik</span></td></tr>
</table>

<div style="text-align:center">
<a href="/modules/surat_undangan_print.php?id=<?= $data['id']; ?>"
   target="_blank"
   class="btn-preview">
📄 Preview Surat
</a>
</div>

</div>

<div style="background:#f9fafb;padding:16px;text-align:center;font-size:12px">
Dokumen ini ditandatangani secara elektronik oleh<br>
<b>Sistem Informasi Desa Mambu</b>
</div>

</div>

</body>
</html>