<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Payment Cancelled | Premium Checkout</title>
    <!-- Tailwind CSS for Modern Styling -->
    <script src="https://cdn.tailwindcss.com"></script>
    <style>
        @keyframes scaleIn {
            0% { transform: scale(0.9); opacity: 0; }
            100% { transform: scale(1); opacity: 1; }
        }
        .animate-scale { animation: scaleIn 0.5s ease-out forwards; }
        .glass {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            border: 1px solid rgba(255, 255, 255, 0.2);
        }
        .progress-bar {
            height: 4px;
            background: #ef4444;
            width: 100%;
            transform-origin: left;
            animation: shrink 5s linear forwards; /* Increased to 5s to give user time to read details */
        }
        @keyframes shrink {
            from { transform: scaleX(1); }
            to { transform: scaleX(0); }
        }
    </style>
</head>
<body class="bg-slate-50 flex items-center justify-center min-h-screen font-sans">

    <div class="max-w-md w-full p-8 mx-4 glass rounded-3xl shadow-2xl text-center animate-scale">
        <!-- Animated Cancel Icon -->
        <div class="mb-6 flex justify-center">
            <div class="rounded-full bg-red-100 p-4">
                <svg class="w-16 h-16 text-red-500" fill="none" stroke="currentColor" stroke-width="3" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" d="M6 18L18 6M6 6l12 12"></path>
                </svg>
            </div>
        </div>

        <!-- Text Content -->
        <h1 class="text-3xl font-bold text-gray-800 mb-2">Payment Cancelled</h1>
        <p class="text-gray-500 mb-6 leading-relaxed">
            Your transaction was not completed. No charges were made to your account.
        </p>

        <!-- Dynamic Transaction Details -->
        <div class="text-left bg-gray-50 rounded-2xl p-4 mb-6 border border-gray-100 space-y-2">
            <div class="flex justify-between text-sm">
                <span class="text-gray-400">Transaction ID:</span>
                <span class="font-mono font-medium text-gray-700" id="display-txid">---</span>
            </div>
            <div class="flex justify-between text-sm">
                <span class="text-gray-400">Amount:</span>
                <span class="font-bold text-gray-700" id="display-amount">$0.00</span>
            </div>
            <div class="flex justify-between text-sm">
                <span class="text-gray-400">Method:</span>
                <span class="capitalize font-medium text-gray-700" id="display-method">---</span>
            </div>
        </div>

        <!-- Redirect Status -->
        <div class="bg-gray-100 rounded-xl p-4 mb-6 relative overflow-hidden">
            <p class="text-sm text-gray-600 font-medium relative z-10">
                Redirecting to home in <span id="timer">5</span>s...
            </p>
            <div class="progress-bar absolute bottom-0 left-0"></div>
        </div>

        <!-- Manual Button -->
        <a href="/index.php" class="inline-block w-full py-3 px-6 text-white bg-gray-900 hover:bg-gray-800 rounded-xl font-semibold transition duration-200 shadow-lg">
            Return to Store
        </a>
    </div>

    <script>
        // 1. Get URL Parameters
        const urlParams = new URLSearchParams(window.location.search);
        const txId = urlParams.get('transactionId') || 'N/A';
        const amount = urlParams.get('paymentAmount') || '0';
        const method = urlParams.get('paymentMethod') || 'Unknown';

        // 2. Display the data
        document.getElementById('display-txid').textContent = txId;
        document.getElementById('display-amount').textContent = `$${amount}`;
        document.getElementById('display-method').textContent = method;

        // 3. Countdown & Redirect Logic
        let timeLeft = 5; // Increased slightly so they can read the ID
        const timerDisplay = document.getElementById('timer');

        const countdown = setInterval(() => {
            timeLeft--;
            if (timerDisplay) timerDisplay.textContent = timeLeft;
            
            if (timeLeft <= 0) {
                clearInterval(countdown);
                window.location.href = '/index.php';
            }
        }, 1000);

        // Safety backup redirect
        setTimeout(() => {
            window.location.href = '/index.php';
        }, 5000);
    </script>
</body>
</html>
