<?php
ini_set('display_errors', 1);
include(__DIR__ . '/../includes/functions.php');

$file_path = (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] !== 'off') ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/';

$appApiEndpoint = $file_path . 'config.php' . '?code=betbetbet';

// Fetch all entries from 'app_dns' table (though it's not used directly here)
$res = $db->select('app_dns', '*', '', '');

// Initialize an array to hold app images
$appImages = []; 
foreach ($res as $row) {
    // Fetch all images from 'app_image' table
    $appImagesResult = $db->select('app_image', '*', '');
    foreach ($appImagesResult as $imageRow) {
        $appImages[] = $imageRow;
    }
}

// Initialize 'app_image' data with empty strings
$app_image_data = [
    "app_img" => "",
    "app_video" => "",
    "app_logo" => "",
    "app_mobile_icon" => "",
    "app_tv_banner" => "",
    "splash_image" => "",
    "back_image" => "",
];

// Populate 'app_image' data if images are available
if (!empty($appImages)) {
    // Assuming we use the first image record
    $firstImage = $appImages[0];
    $app_image_data['app_img'] = isset($firstImage['app_img']) ? $firstImage['app_img'] : '';
    $app_image_data['app_video'] = isset($firstImage['app_video']) ? $firstImage['app_video'] : '';
    $app_image_data['app_logo'] = isset($firstImage['app_logo']) ? $firstImage['app_logo'] : '';
    $app_image_data['app_mobile_icon'] = isset($firstImage['app_mobile_icon']) ? $firstImage['app_mobile_icon'] : '';
    $app_image_data['app_tv_banner'] = isset($firstImage['app_tv_banner']) ? $firstImage['app_tv_banner'] : '';
    $app_image_data['splash_image'] = isset($firstImage['splash_image']) ? $firstImage['splash_image'] : '';
    $app_image_data['back_image'] = isset($firstImage['back_image']) ? $firstImage['back_image'] : '';
}

$data = [
    "endpoint" => [
        "verifyDevice" => "https://login.purpletv.app/api/verifyDeviceCode",
        "playlist" => "https://login.purpletv.app/api/playlistByDevice",
        "mackey" => "https://login.purpletv.app/api/playlistByMacKey",
        "qr_data" => "https://login.purpletv.app",
        "register" => "https://cloud.purpletv.app/register",
        "login" => "https://cloud.purpletv.app/login",
        "create_playlist" => "https://cloud.purpletv.app/createplaylist",
        "create_subprofile" => "https://cloud.purpletv.app/subprofile",
        "create_history" => "https://cloud.purpletv.app/createhistory",
        "create_fav" => "https://cloud.purpletv.app/createfavorites",
        "update_playlist" => "https://cloud.purpletv.app/updateplaylist",
        "get_subprofile" => "https://cloud.purpletv.app/getsubprofile",
        "list_get" => "https://cloud.purpletv.app/getList",
        "list_m3u_update" => "https://cloud.purpletv.app/m3u",
        "deleteurl" => "https://cloud.purpletv.app/deleteurl",
        "list_xstream_update" => "https://cloud.purpletv.app/xstream",
        "app_api_endpoint" => "$appApiEndpoint"
    ],
    "flag" => [
        "login_id_pin" => false,
        "login_activate" => false,
        "login_qr" => false,
        "login_code_universal" => false,
        "login_mac_key" => false,
    ],
    "content" => [
        "qr_step" => "1) Open https://form.purpletv.app/ in browser2) Add Six digit code in form'3) Add Xtream or M3u details and 'Submit'4) Screen will Refresh and Show your playlist profile",
        "mackey_step" => "1) Register or Login at https://login.purpletv.app/login2) Navigate To Playlist > Add New Playlist and then My Devices > Add New Device. 3) Enter Device Id and Device Key and Choose your playlist and 'Submit'.",
        "activation_step" => "1) Register or Login at https://login.purpletv.app/login2) Click To 'Add New Device' And 'Add New Playlist'3) Assign Devices To Playlist and 'Submit'4) Enter the 'Device Code' in the box below",
        "ads_txt" => "display your ads heresupport@purplesmarttv.com",
        "legal_msg" => "<h3>Purple Player doesn't sell playlist or subscriptions</h3></br>Purple Player is a General Media Player and it doesn't include any content or playlist",
    ],
    "language" => [
        "defult_language" => "EN",
        "firstime_select_language" => "false",
    ],
    "ads" => [
        "ads_app_id" => "",
        "ads_banner" => "/200463343/300x250_inHouse_banner",
        "ads_banner_mobile" => "/200463343/300x250_inHouse_banner",
        "ads_intrestial" => "",
        "ads_rewarded" => "",
        "ads_native" => "",
        "ads_intrestial_time_delay" => "10",
        "ads_ios_status" => "false",
        "ads_status" => "false",
        "vast_ads" => [
            "live_tv" => [
                "app_vast_ads_s_status" => "false",
                "app_vast_ads_s_full" => "false",
                "app_vast_ads_s" => "https://pubads.g.doubleclick.net/gampad/live/ads?...",
                "app_vast_ads_h_status" => "true",
                "app_vast_ads_h" => "https://pubads.g.doubleclick.net/gampad/live/ads?...",
            ],
            "vod" => [
                "app_vast_ads_s_status" => "false",
                "app_vast_ads_s" => "https://pubads.g.doubleclick.net/gampad/live/ads?...",
                "app_vast_ads_h_status" => "true",
                "app_vast_ads_h" => "https://pubads.g.doubleclick.net/gampad/live/ads?...",
            ],
            "show" => [
                "app_vast_ads_s_status" => "false",
                "app_vast_ads_s" => "https://pubads.g.doubleclick.net/gampad/live/ads?...",
                "app_vast_ads_h_status" => "true",
                "app_vast_ads_h" => "https://pubads.g.doubleclick.net/gampad/live/ads?...",
            ],
            "fallback" => "https://pubads.g.doubleclick.net/gampad/live/ads?...",
            "fallback_backup" => "https://pubads.g.doubleclick.net/gampad/live/ads?...",
        ],
    ],
    "version" => [
        "version_check" => "false",
        "version_code" => "7",
        "version_name" => "7.0",
        "version_download_url" => "https://tinyurl.com/purpleiptv1",
        "version_download_url_apk" => "",
        "version_force_update" => "false",
        "version_update_msg" => "Please Update for looking Glass",
        "version_changelog" => [],
    ],
    "player" => [
        "live_tv" => "Vlc Player",
        "vod" => "Vlc Player",
        "series" => "Exo Player",
        "catch_up" => "Exo Player",
    ],
    "app_announce" => [],
    "maintenance_msg" => [],
    "app_image" => [
        "app_img" => "false",
        "app_logo" => "",
        "app_mobile_icon" => "",
        "app_tv_banner" => "",
        "splash_image" => "",
        "back_image" => "",

    ],
    
    "api_key" => [
        "imdb_api" => "",
        "g_api_key" => "",
        "image_imdb" => "",
        "trakt_api_key" => "",
        "weather_api" => "",
        "ip_stack_key" => "",
        "check_ip" => "https://checkip.justwatch.com",
        "vpn_url" => "https://panel.purpletv.app/api/vpn",
        "vpn" => "true",
        "vpn_username" => "#",
        "vpn_password" => "#",
        "analyt_key" => "181b306d2ea13f466b5e28a70d9df96858790acd",
        "analyt_server" => "http://countly.guidemefast.com",
        "appcenter" => "c5b165ad-397f-4531-b144-2cc56406645f",
    ],
    "weather" => [
        "city_name" => "",
        "city_id" => "",
    ],
    "agreement" => [
        "privacy_policy" => "https://www.iubenda.com/privacy-policy/68919995",
        "terms_condtion" => "",
        "copyright_complaint" => "",
    ],
];

header('Content-Type: application/json');
echo json_encode($data, JSON_PRETTY_PRINT);
?>
