<?php
// =============================================================================
// /Ibo_ultra/webview.php?fetch=<type>
//
// The IBO Ultra app does NOT respect home_url2 from /auth for its Sports
// button — instead it builds a hardcoded URL by appending
//     webview.php?fetch=<type>
// to the panel base. The known fetch types (captured live from the original wire):
//     fetch=sport            → live + today's sport widget
//     fetch=background_alt   → TMDB rotating backdrop
//
// This dispatcher just forwards to the matching /api/webview endpoint so the
// same HTML the admin previews in the panel is what the device gets.
// =============================================================================

$fetch = isset($_GET['fetch']) ? strtolower(trim((string)$_GET['fetch'])) : '';

$routes = [
    'sport'           => __DIR__ . '/api/webview/sports/sport_top.php',
    'sport_top'       => __DIR__ . '/api/webview/sports/sport_top.php',
    'sport_tv_today'  => __DIR__ . '/api/webview/sports/sport_tv_today.php',
    'sport_l_table'   => __DIR__ . '/api/webview/sports/sport_l_table.php',
    'sport_dashboard' => __DIR__ . '/api/webview/sports/dashboard.php',
    'background'      => __DIR__ . '/api/webview/tmdb/autoads_0.php',
    'background_alt'  => __DIR__ . '/api/webview/tmdb/autoads_0.php',
    'tmdb'            => __DIR__ . '/api/webview/tmdb/autoads_0.php',
    'slideshow'       => __DIR__ . '/api/webview/slideshow.php',
    'frameview'       => __DIR__ . '/api/webview/frameview.php',
];

if (!isset($routes[$fetch])) {
    header('Content-Type: text/plain; charset=utf-8', true, 404);
    echo "unknown fetch type: " . htmlspecialchars($fetch, ENT_QUOTES, 'UTF-8');
    exit;
}

$target = $routes[$fetch];
if (!is_file($target)) {
    header('Content-Type: text/plain; charset=utf-8', true, 500);
    echo "route registered but file missing: " . basename($target);
    exit;
}

require $target;
