<?php
include('../../includes/layout_inicio.php');
require_once('../../config/conexao.php');

// PEGA ID DO EVENTO
$evento_id = $_GET['evento_id'] ?? 0;

// BUSCA EVENTO
$stmt = $pdo->prepare("SELECT * FROM eventos WHERE id = :id");
$stmt->execute(['id' => $evento_id]);
$evento = $stmt->fetch();

if(!$evento){
    echo "<p>Evento não encontrado</p>";
    include('../../includes/layout_fim.php');
    exit;
}

// URL QUE O QR CODE VAI APONTAR
$url = "http://localhost/sistema_licolico/presenca_qrcode/presenca/registrar.php?evento_id=" . $evento_id;

// QR CODE VIA API
$qr = "https://chart.googleapis.com/chart?chs=300x300&cht=qr&chl=" . urlencode($url);
?>

<h1>QR Code do Evento</h1>

<div class="card">

    <h3><?= $evento['nome'] ?></h3>
    <p><?= date('d/m/Y', strtotime($evento['data_evento'])) ?></p>

    <br>

    <img src="<?= $qr ?>" alt="QR Code">

    <br><br>

    <p><strong>Link:</strong></p>
    <input type="text" value="<?= $url ?>" readonly style="width:100%; padding:8px;">

</div>

<?php include('../../includes/layout_fim.php'); ?>