<?php
define('SECURE_ACCESS', true);
require_once __DIR__ . '/../includes/config.php';
require_once __DIR__ . '/../includes/database.php';
require_once __DIR__ . '/../includes/functions.php';

$page_title = 'Ofertas';
$db = db();

$stmt = $db->prepare('SELECT p.*, c.nombre AS categoria_nombre, c.slug AS categoria_slug, m.nombre AS marca_nombre, m.slug AS marca_slug FROM productos p JOIN categorias c ON p.categoria_id = c.id JOIN marcas m ON p.marca_id = m.id WHERE p.activo = 1 AND p.en_oferta = 1 ORDER BY p.fecha_creacion DESC');
$stmt->execute();
$productos = $stmt->fetchAll();

require_once __DIR__ . '/../includes/header.php';
?>
<section class="page-header"><div class="container"><h1>Ofertas Especiales</h1><nav aria-label="breadcrumb"><ol class="breadcrumb mb-0"><li class="breadcrumb-item"><a href="<?= url('') ?>">Inicio</a></li><li class="breadcrumb-item active">Ofertas</li></ol></nav></div></section>
<section class="py-5">
  <div class="container">
    <?php if (empty($productos)): ?>
      <div class="empty-state"><i class="bi bi-tag"></i><h4>No hay ofertas disponibles</h4><p class="text-muted">Vuelve pronto para ver nuevas promociones.</p></div>
    <?php else: ?>
      <div class="row g-3">
        <?php foreach ($productos as $p): ?>
          <div class="col-6 col-md-4 col-lg-3"><?php include __DIR__ . '/../includes/product-card.php'; ?></div>
        <?php endforeach; ?>
      </div>
    <?php endif; ?>
  </div>
</section>
<?php require_once __DIR__ . '/../includes/footer.php'; ?>
