<?php
// api/get_active_gifts.php - 前台專用：取得目前上架的禮品清單
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
error_reporting(0);
require_once 'db.php';

try {
    // 只撈取 is_active = 1 的商品，並依照價格由低到高排序
    $stmt = $pdo->query("SELECT * FROM gifts WHERE is_active = 1 ORDER BY cost ASC");
    $gifts = $stmt->fetchAll(PDO::FETCH_ASSOC);
    
    echo json_encode(["status" => "success", "data" => $gifts]);
} catch (Exception $e) {
    echo json_encode(["status" => "error", "message" => "無法讀取禮品清單"]);
}
?>