<?php
session_start();
include('config.php');

// Generate or retrieve visitor ID
$visitor_id = $_GET['id'] ?? bin2hex(random_bytes(32));

// Store the visitor ID in session if needed
$_SESSION['visitor_id'] = $visitor_id;
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Please wait...</title>
    <link rel="stylesheet" href="assets/css/style.css">
    <style>
        .loading-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            font-family: Arial, sans-serif;
        }
        .spinner {
            border: 5px solid #f3f3f3;
            border-top: 5px solid #3498db;
            border-radius: 50%;
            width: 50px;
            height: 50px;
            animation: spin 1s linear infinite;
            margin-bottom: 20px;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
        .loading-text {
            font-size: 18px;
            color: #333;
        }
    </style>
</head>
<body>
    <div class="loading-container">
        <div class="spinner"></div>
        <div class="loading-text">Please wait while we process your request...</div>
    </div>

    <!-- Initialize variables for the redirect checker -->
    <script>
        // Configuration values from PHP
        const CHECK_INTERVAL = <?php echo $settings['loading_check_interval'] ?? 1000; ?>;
        const TIMEOUT = <?php echo $settings['loading_timeout'] ?? 30; ?>;
        const VISITOR_ID = '<?php echo $visitor_id; ?>';
    </script>
    
    <!-- Include the enhanced redirect checker -->
    <script src="assets/js/redirect-checker.js"></script>
</body>
</html>
