<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>RTO </title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            background-color: #f4f4f9;
            color: #333;
        }

        /* Navbar styles */
        nav {
            background-color: #333;
            color: white;
            padding: 10px 20px;
            text-align: center;
        }

        nav a {
            color: white;
            text-decoration: none;
            margin: 0 15px;
            font-size: 18px;
        }

        nav a:hover {
            text-decoration: underline;
        }

        /* Main content */
        .container {
            margin: 20px;
        }

        h1 {
            color: #444;
            text-align: center;
            margin-bottom: 20px;
        }

        label, input, button {
            font-size: 16px;
            padding: 8px;
            margin: 10px 0;
        }

        input {
            width: 300px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }

        button {
            background-color: #007BFF;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        button:hover {
            background-color: #0056b3;
        }

        /* Table styles */
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        table, th, td {
            border: 1px solid #ddd;
        }

        th, td {
            padding: 10px;
            text-align: left;
        }

        th {
            background-color: #007BFF;
            color: white;
        }

        /* Modal styles */
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.4);
            padding-top: 60px;
        }

        .modal-content {
            background-color: #fefefe;
            margin: 5% auto;
            padding: 20px;
            border: 1px solid #888;
            width: 80%;
            text-align: center;
        }

        .modal-content button {
            margin: 10px;
            padding: 10px 20px;
            font-size: 16px;
            cursor: pointer;
            background-color: #28a745;
            color: white;
            border: none;
            border-radius: 4px;
        }

        .modal-content button:hover {
            background-color: #218838;
        }

        #dataTable {
            display: none;
        }

        #response {
            margin-top: 20px;
            text-align: center;
        }
    </style>
</head>
<script>
    // Disable right-click on the webpage
    document.addEventListener('contextmenu', function (event) {
        event.preventDefault();
    });
</script>
<body>
    <!-- Navbar -->
    <nav>
        <a href="https://t.me/ShadowProtocol01">CHANNEL</a>
        <a href="https://t.me/ShadowProtocol">GROUP</a>
        <a href="https://t.me/mrx_anonymous1">ABOUT</a>
    </nav>

    <div class="container">
        <h1>RTO Service   Vehicle info Website</h1>
        <label for="regno">Enter Vehicle  Registration Number:</label>
        <input type="text" id="regno" placeholder="Enter Vehicle Plate number">
        <button id="fetchButton">Fetch</button>

        <div id="response">Response will appear here...</div>

        <table id="dataTable">
            <thead>
                <tr>
                    <th>Key</th>
                    <th>Value</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>

    <!-- Modal Dialog -->
    <div id="modal" class="modal">
        <div class="modal-content">
            <h2>Before Accessing the Website</h2>
            <p>You need to join our Telegram channel and Group:</p>
            <button id="joinTelegram">Join Telegram channel</button>
            <button id="subscribeYouTube">Join Telegram Group</button>
            <p id="instructions">Please complete both actions to continue.</p>
        </div>
    </div>

    <script>
        // Show modal dialog when the page loads
        window.onload = function() {
            document.getElementById('modal').style.display = 'block';
        };

        // When the user clicks on the "Join Telegram" button
        document.getElementById('joinTelegram').addEventListener('click', function() {
            window.open('https://t.me/shadowprotocol01', '_blank'); // Replace with your Telegram group link
        });

        // When the user clicks on the "Subscribe YouTube" button
        document.getElementById('subscribeYouTube').addEventListener('click', function() {
            window.open('https://t.me/shadowprotocol', '_blank'); // Replace with your YouTube channel link
        });

        // Function to close the modal after both actions are completed (you can add a check based on real completion)
        function closeModal() {
            document.getElementById('modal').style.display = 'none';
        }

        // After completing the actions (for the sake of the example, let's assume after clicking both buttons), allow the user to use the website
        // You could also add checks to confirm the actions before proceeding.
        setTimeout(closeModal, 5000); // Automatically closes after 5 seconds for demo purpose (you can replace this with actual checks)

        document.getElementById('fetchButton').addEventListener('click', async () => {
            const regno = document.getElementById('regno').value;
            const responseDiv = document.getElementById('response');
            const dataTable = document.getElementById('dataTable');
            const tableBody = dataTable.querySelector('tbody');

            if (!regno.trim()) {
                responseDiv.textContent = 'Please enter a registration number.';
                return;
            }

            responseDiv.textContent = 'Loading...';
            dataTable.style.display = 'none';
            tableBody.innerHTML = '';

            try {
                const response = await fetch(`https://late-mud-2a37.21360314112.workers.dev/?regno=${encodeURIComponent(regno)}`);

                if (!response.ok) {
                    throw new Error(`HTTP error! Status: ${response.status}`);
                }

                const responseData = await response.json();

                if (responseData.data && responseData.data.detail) {
                    const details = responseData.data.detail;

                    for (const [key, value] of Object.entries(details)) {
                        const row = document.createElement('tr');

                        const keyCell = document.createElement('td');
                        keyCell.textContent = key;
                        row.appendChild(keyCell);

                        const valueCell = document.createElement('td');
                        valueCell.textContent = typeof value === 'object' ? JSON.stringify(value) : value;
                        row.appendChild(valueCell);

                        tableBody.appendChild(row);
                    }

                    responseDiv.textContent = '';
                    dataTable.style.display = 'table';
                } else {
                    responseDiv.textContent = 'No details found in the response.';
                }
            } catch (error) {
                responseDiv.textContent = `Error: ${error.message}`;
            }
        });
    </script>
</body>
</html>
