<?php
session_start();
if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') {
    header("Location: ../auth/login.php");
    exit();
}

require_once __DIR__ . '/../../controllers/GiftController.php';
$giftController = new GiftController();
$gifts = $giftController->getGifts();
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Gestión de Regalos</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <h1 class="mt-3">Gestión de Regalos</h1>
        <table class="table">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Nombre</th>
                    <th>Costo en Puntos</th>
                    <th>Regalo de Cumpleaños</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($gifts as $gift): ?>
                    <tr>
                        <td><?php echo $gift['id']; ?></td>
                        <td><?php echo $gift['name']; ?></td>
                        <td><?php echo $gift['points_cost']; ?></td>
                        <td><?php echo $gift['birthday_gift'] ? 'Sí' : 'No'; ?></td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        <a href="dashboard.php" class="btn btn-primary">Volver al Dashboard</a>
    </div>
</body>
</html>