<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>KING TRADING FUTURE SIGNAL GENERATOR</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background: radial-gradient(circle, #000000, #1a1a1a, #333333);
            color: #ecf0f1;
            text-align: center;
            padding: 20px;
        }

        h1 {
            font-size: 2.5rem;
            margin-bottom: 10px;
            text-shadow: 0 0 15px #f39c12, 0 0 30px #3498db;
        }

        h1 span.gold {
            color: #f1c40f;
            text-shadow: 0 0 15px #f39c12, 0 0 30px #f1c40f;
        }

        h1 span.blue {
            color: #3498db;
            text-shadow: 0 0 15px #3498db, 0 0 30px #2980b9;
        }

        p {
            font-size: 1.2rem;
            color: #bdc3c7;
            margin-bottom: 20px;
            font-family: 'Courier New', Courier, monospace;
            font-weight: bold;
        }

        #currency-list {
            display: flex;
            flex-wrap: wrap;
            justify-content: center;
            gap: 10px;
        }

        #currency-list div {
            padding: 10px 15px;
            background: #1a1a1a;
            border: 2px solid #f1c40f;
            border-radius: 10px;
            color: #f1c40f;
            font-size: 1rem;
            cursor: pointer;
            transition: all 0.3s ease-in-out;
            text-align: center;
        }

        #currency-list div:hover {
            background: #f1c40f;
            color: #1a1a1a;
            box-shadow: 0 0 15px #f1c40f;
        }

        #currency-list div.selected {
            background: #f1c40f;
            color: #1a1a1a;
        }

        select {
            background: #1a1a1a;
            color: #f1c40f;
            border: 1px solid #f1c40f;
            border-radius: 5px;
            padding: 5px;
            margin-top: 10px;
            cursor: pointer;
        }

        button {
            margin: 10px;
            padding: 10px 20px;
            font-size: 1rem;
            color: #ffffff;
            background: linear-gradient(135deg, #e67e22, #d35400);
            border: none;
            border-radius: 10px;
            cursor: pointer;
            box-shadow: 0 0 15px #e67e22;
            transition: all 0.3s ease-in-out;
        }

        button:hover {
            background: linear-gradient(135deg, #d35400, #e67e22);
            box-shadow: 0 0 20px #d35400;
        }

        #loading-spinner {
            display: none;
            margin: 20px auto;
            width: 50px;
            height: 50px;
            border: 5px solid rgba(0, 0, 0, 0.1);
            border-radius: 50%;
            border-top-color: #f1c40f;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            to {
                transform: rotate(360deg);
            }
        }

        #trades div {
            margin: 10px auto;
            padding: 10px;
            background: #1a1a1a;
            border: 2px solid #f1c40f;
            border-radius: 10px;
            color: #ecf0f1;
            font-size: 1rem;
            text-align: center;
            box-shadow: 0 0 10px #f1c40f;
            width: 250px;
        }

        /* Style for the modal */
        .modal {
            display: none;
            position: fixed;
            z-index: 1;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            overflow: auto;
            background-color: rgba(0, 0, 0, 0.5);
            padding-top: 60px;
        }

        .modal-content {
            background-color: #1a1a1a;
            margin: 5% auto;
            padding: 20px;
            border: 1px solid #f1c40f;
            width: 40%;
            text-align: center;
            border-radius: 10px;
            color: #f1c40f;
        }

        .close {
            color: #f1c40f;
            font-size: 28px;
            font-weight: bold;
            cursor: pointer;
        }

        .close:hover,
        .close:focus {
            color: #f39c12;
            text-decoration: none;
            cursor: pointer;
        }
    </style>
</head>
<body>
    <h1>
        <span class="gold">KING TRADING</span> 
        <span class="blue">FUTURE SIGNAL GENERATOR</span>
    </h1>
    <p>Signals are valid for OTC market on QUOTEX platform only.</p>
    <div id="currency-list"></div>
    <button id="generate-btn" onclick="generateTrades()" disabled>Generate Signals</button>
    <div id="loading-spinner"></div>
    <div id="trades"></div>
    <button id="copy-btn" onclick="copyTrades()">Copy Signals</button>

    <!-- Modal for selecting direction -->
    <div id="direction-modal" class="modal">
        <div class="modal-content">
            <span class="close" onclick="closeModal()">&times;</span>
            <p>Select direction for <span id="modal-pair"></span></p>
            <select id="direction-select">
                <option value="CALL">CALL</option>
                <option value="PUT">PUT</option>
            </select>
            <button onclick="saveDirection()">Save Direction</button>
        </div>
    </div>

    <script>
        const pairs = [
            "CAD/CHF (OTC)", "CAD/JPY (OTC)", "CHF/JPY (OTC)", "USD/BDT (OTC)",
            "USD/BRL (OTC)", "USD/COP (OTC)", "USD/DZD (OTC)", "USD/EGP (OTC)"
        ];

        const selectedPairs = new Set();
        const pairDirections = new Map(); // Map to store direction for each pair

        let currentPair = ''; // Store the pair for which direction is being set

        function renderCurrencyPairs() {
            const currencyList = document.getElementById('currency-list');
            pairs.forEach(pair => {
                const item = document.createElement('div');
                item.textContent = pair;

                item.onclick = () => {
                    // If already selected, unselect it
                    if (selectedPairs.has(pair)) {
                        selectedPairs.delete(pair);
                        item.classList.remove('selected');
                        pairDirections.delete(pair); // Remove direction when unselected
                        if (pairDirections.size < 4) {
                            document.getElementById('generate-btn').disabled = true;
                        }
                    } else {
                        // If less than 4 pairs selected, add the pair
                        if (selectedPairs.size < 4) {
                            selectedPairs.add(pair);
                            item.classList.add('selected');
                            openModal(pair);
                        }
                    }
                };
                currencyList.appendChild(item);
            });
        }

        function openModal(pair) {
            currentPair = pair;
            document.getElementById('modal-pair').textContent = pair;
            document.getElementById('direction-modal').style.display = 'block';
        }

        function closeModal() {
            document.getElementById('direction-modal').style.display = 'none';
        }

        function saveDirection() {
            const direction = document.getElementById('direction-select').value;
            pairDirections.set(currentPair, direction);
            if (pairDirections.size === 4) {
                document.getElementById('generate-btn').disabled = false; // Enable generate button when all directions are set
            }
            closeModal();
        }

        function generateTrades() {
            if (selectedPairs.size !== 4 || pairDirections.size !== 4) {
                alert("You must select exactly 4 pairs and set directions for each.");
                return;
            }

            const loadingSpinner = document.getElementById('loading-spinner');
            const tradesContainer = document.getElementById('trades');
            tradesContainer.innerHTML = '';
            loadingSpinner.style.display = 'block';

            const now = new Date();
            const endTime = new Date(now.getTime() + 60 * 60 * 1000); // 1 hour from now
            const signals = [];
            const selected = Array.from(selectedPairs);

            let currentTime = new Date(now.getTime());
            while (currentTime < endTime) {
                const pair = selected[Math.floor(Math.random() * selected.length)];
                const timeString = currentTime.toTimeString().slice(0, 5);
                const direction = pairDirections.get(pair); // Get the selected direction for this pair

                signals.push(`${pair} ➪ ${timeString} ${direction}`);
                currentTime.setMinutes(currentTime.getMinutes() + Math.floor(Math.random() * 10) + 1);
            }

            setTimeout(() => {
                loadingSpinner.style.display = 'none';
                signals.forEach(signal => {
                    const div = document.createElement('div');
                    div.textContent = signal;
                    tradesContainer.appendChild(div);
                });
            }, 15000);
        }

        function copyTrades() {
            const trades = Array.from(document.getElementById('trades').children)
                .map(div => div.textContent)
                .join('\n');

            navigator.clipboard.writeText(trades).then(() => {
                alert("Signals copied successfully!");
            }).catch(() => {
                alert("Error copying signals.");
            });
        }

        renderCurrencyPairs();
    </script>
</body>
</html>