<?php
require __DIR__ . '/_boot.php';
require __DIR__ . '/partials/nav.php';
if (!$user) { header('Location: login-dev.php'); exit; }
$token = $user['qr_token'] ?: ('PYRK-USER-' . (int)$user['id']);
?>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>My Pyrk QR</title><link rel="stylesheet" href="assets/css/app.css"></head><body>
<?php pyrk_render_nav('client'); ?>
<main class="container narrow">
  <section class="panel qr-page">
    <p class="eyebrow">Member check-in QR</p>
    <h1><?= htmlspecialchars($user['full_name']) ?></h1>
    <p class="muted">Show this QR code to the Pyrk walk leader at check-in.</p>
    <div id="memberQr" class="member-qr" data-token="<?= htmlspecialchars($token) ?>"></div>
    <code class="qr-token"><?= htmlspecialchars($token) ?></code>
  </section>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
<script>
const el = document.getElementById('memberQr');
if (window.QRCode) new QRCode(el, {text: el.dataset.token, width: 240, height: 240});
else el.innerHTML = '<p>QR library unavailable. Use the text token below.</p>';
</script>
</body></html>
