<?php
require_once __DIR__ . '/../config/database.php';
require_once __DIR__ . '/../config/constants.php';
require_once __DIR__ . '/../includes/functions.php';

apply_cors();

if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
    send_error('Method not allowed.', 405);
}

$pdo = getDbConnection();
$stmt = $pdo->query(
    "SELECT id, title, description, image_url, button_text, button_url, display_order
     FROM banners
     WHERE is_active = 1
       AND (start_date IS NULL OR start_date <= CURDATE())
       AND (end_date IS NULL OR end_date >= CURDATE())
     ORDER BY display_order ASC"
);

send_success(['banners' => $stmt->fetchAll()]);
