<?php
/**
 * sports.php — Sports guide configuration API endpoint
 * 
 * Called by the app at: {panel_url}api/sports.php?config=1
 * Returns JSON configuration for the in-app sports WebView.
 */

require_once __DIR__ . '/../includes/functions.php';

header('Content-Type: application/json; charset=UTF-8');

logRequest('api/sports.php');

if (!isset($_GET['config'])) {
    echo json_encode(['success' => false, 'error' => 'Missing parameter']);
    exit;
}

// Sports is ALWAYS enabled. The app's Sports menu loads the sport-tv-guide
// widget (sport.php) — a full-viewport iframe around the sport-tv-guide.live
// widget, same as the XCIPTV panel. NOTE: sport.php is at the PANEL ROOT,
// NOT api/sport.php (which is the JSON config endpoint). Go up one dir from /api.
$scheme = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? 'https' : 'http';
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
$base = rtrim(dirname(dirname($_SERVER['SCRIPT_NAME'])), '/\\');
$url = $scheme . '://' . $host . $base . '/sport.php';

echo json_encode([
    'success' => true,
    'enabled' => true,
    'title' => 'Sports',
    'url' => $url,
    'javascript' => true,
    'allow_external' => false,
    'user_agent' => '',
    'maintenance_message' => '',
    'cache_mode' => 'default',
], JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
