<?php
header('Content-Type: application/json; charset=utf-8');
require_once __DIR__ . '/../admin/db.php';

$rasca_id = (int)($_GET['rasca_id'] ?? 0);
if ($rasca_id <= 0) { echo json_encode(['error'=>'rasca_id inválido']); exit; }

$stmt = $conn->prepare("SELECT rasca_id,nombre,banner_1,banner_2,banner_3,banner_4,background_image,fullscreen_icon,fg_image,bg_image FROM rasca_config WHERE rasca_id=?");
$stmt->bind_param("i", $rasca_id);
$stmt->execute();
$cfg = $stmt->get_result()->fetch_assoc();

if(!$cfg){
  // Fallbacks por defecto
  $cfg = [
    'rasca_id'=>$rasca_id,'nombre'=>'Rasca',
    'banner_1'=>'/ruleta/img/BANNER-1.png','banner_2'=>'/ruleta/img/BANNER-2.png',
    'banner_3'=>'/ruleta/img/BANNER-3.png','banner_4'=>'/ruleta/img/BANNER-4.png',
    'background_image'=>null,'fullscreen_icon'=>'/ruleta/img/fullscreen-icon.png',
    'fg_image'=>null,'bg_image'=>null
  ];
}

echo json_encode($cfg, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
