<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Coders Hosting Panel</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"></link>
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Roboto', sans-serif;
        }
        .status {
            transition: all 0.3s ease-in-out;
        }
        .status.active {
            color: #34D399;
        }
        .status.inactive {
            color: #F87171;
        }
        .logs ul {
            list-style-type: none;
            padding: 0;
        }
        .logs ul li {
            margin-bottom: 0.5rem;
        }
        .logs ul li::before {
            content: "";
            margin-right: 0.5rem;
        }
        .status-animation {
            display: inline-block;
            width: 1rem;
            height: 1rem;
            border-radius: 50%;
            margin-left: 0.5rem;
            animation: pulse 1.5s infinite;
        }
        .status-animation.active {
            background-color: #34D399;
        }
        .status-animation.inactive {
            background-color: #F87171;
        }
        @keyframes pulse {
            0%, 100% {
                transform: scale(1);
            }
            50% {
                transform: scale(1.5);
            }
        }
        .alert {
            display: none;
            position: fixed;
            top: 20px;
            right: 20px;
            padding: 20px;
            background-color: #34D399;
            color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
            animation: slideIn 0.5s forwards;
        }
        .alert.show {
            display: block;
        }
        .alert.error {
            background-color: #F87171;
        }
        @keyframes slideIn {
            from {
                opacity: 0;
                transform: translateX(100%);
            }
            to {
                opacity: 1;
                transform: translateX(0);
            }
        }
    </style>
</head>
<body class="bg-gray-900 flex items-center justify-center min-h-screen">
    <div id="loginPanel" class="container max-w-md mx-auto bg-gray-800 p-12 rounded-lg shadow-2xl">
        <h1 class="text-4xl font-bold text-center text-white mb-8">Login</h1>
        <form id="loginForm" class="space-y-6">
            <div>
                <label for="email" class="block text-gray-400 font-medium mb-2">Email:</label>
                <input type="email" id="email" name="email" class="w-full p-4 border border-gray-600 rounded-lg bg-gray-700 text-white" required>
            </div>
            <div>
                <label for="password" class="block text-gray-400 font-medium mb-2">Password:</label>
                <input type="password" id="password" name="password" class="w-full p-4 border border-gray-600 rounded-lg bg-gray-700 text-white" required>
            </div>
            <button type="submit" class="w-full py-4 bg-blue-600 text-white font-bold rounded-lg hover:bg-blue-700 transition duration-300">
                Login
            </button>
        </form>
    </div>

    <div id="mainPanel" class="container max-w-4xl mx-auto bg-gray-800 p-12 rounded-lg shadow-2xl hidden">
        <h1 class="text-5xl font-bold text-center text-white mb-8">Coders Hosting Panel</h1>
        <div class="flex space-x-4 mb-8">
            <button id="startButton" class="w-full py-4 bg-green-600 text-white font-bold rounded-lg hover:bg-green-700 transition duration-300 transform hover:scale-105">
                Start
            </button>
            <button id="stopButton" class="w-full py-4 bg-red-600 text-white font-bold rounded-lg hover:bg-red-700 transition duration-300 transform hover:scale-105">
                Stop
            </button>
        </div>
        <div class="status mt-8 p-6 bg-gray-700 rounded-lg text-center text-2xl font-semibold text-gray-300" id="status">
            Status: Checking... <span class="status-animation" id="statusAnimation"></span>
        </div>
        <div class="logs mt-8 p-6 bg-gray-700 rounded-lg text-gray-300 text-sm" id="logs">
            <h2 class="text-2xl font-bold mb-4">Logs:</h2>
            <ul id="logList">
                <li>No logs available</li>
            </ul>
        </div>
    </div>

    <div id="alert" class="alert">
        <i class="fas fa-check-circle"></i> Action completed successfully!
    </div>

    <script>
        const users = [
            { email: "yuvaldora@host.panel.com", password: "ybhost4ga", id: `yuval-dora` },
            { email: "ragedis@host.panel.com", password: "rgpanelgyra", id: `rage` },
            { email: "somin@host.panel.com", password: "smhpliuy", id: `somin-bot` },
            { email: "slixs@host.panel.com", password: "sxpaho4a", id: `slixs` },
            { email: "mrshibolet@host.panel.com", password: "mrpaho7fa", id: `mrshib` },
            { email: "masterohad@host.panel.com", password: "msobroles3", id: `master_ohad_bot` },
            { email: "townzone@host.panel.com", password: "tzopea35a", id: `townzone` },
        ];

        let currentUserId = null;

        document.getElementById('loginForm').addEventListener('submit', function(event) {
            event.preventDefault();
            const email = document.getElementById('email').value;
            const password = document.getElementById('password').value;

            const user = users.find(user => user.email === email && user.password === password);

            if (user) {
                currentUserId = user.id;
                document.getElementById('loginPanel').classList.add('hidden');
                document.getElementById('mainPanel').classList.remove('hidden');
                checkStatus();
            } else {
                showAlert('Invalid email or password', true);
            }
        });

        function showAlert(message, isError = false) {
            const alert = document.getElementById('alert');
            alert.innerHTML = isError ? `<i class="fas fa-times-circle"></i> ${message}` : `<i class="fas fa-check-circle"></i> ${message}`;
            alert.className = isError ? 'alert show error' : 'alert show';
            setTimeout(() => {
                alert.classList.remove('show');
            }, 3000);
        }

        function updateStatus(action, data) {
            const statusElement = document.getElementById('status');
            const statusAnimation = document.getElementById('statusAnimation');
            statusElement.innerText = action === 'start' ? 'Status: Online' : 'Status: Offline';
            statusElement.appendChild(statusAnimation);
            statusAnimation.className = action === 'start' ? 'status-animation active' : 'status-animation inactive';
            const logList = document.getElementById('logList');
            const logItem = document.createElement('li');
            logItem.innerText = `${action} bot`;
            logList.appendChild(logItem);
            showAlert('Action completed successfully!');
        }

        function checkStatus() {
            const action = 'status';

            const url = ` https://true-marginally-bat.ngrok-free.app/${action}/${currentUserId}`;

            fetch(url, {
                method: 'GET',
                headers: {
                    'Content-Type': 'application/json'
                }
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
                return response.json();
            })
            .then(data => {
                const status = data.status ? 'start' : 'stop';
                updateStatus(status, data.message);
            })
            .catch(error => {
                console.error('There was a problem with the fetch operation:', error);
                showAlert('Error: ' + error.message, true);
            });
        }

        document.getElementById('startButton').addEventListener('click', function() {
            const action = 'start';

            const url = ` https://true-marginally-bat.ngrok-free.app/${action}/${currentUserId}`;

            fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                }
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
                return response.text();
            })
            .then(data => {
                updateStatus(action, data);
            })
            .catch(error => {
                console.error('There was a problem with the fetch operation:', error);
                showAlert('Error: ' + error.message, true);
            });
        });

        document.getElementById('stopButton').addEventListener('click', function() {
            const action = 'stop';

            const url = ` https://true-marginally-bat.ngrok-free.app/${action}/${currentUserId}`;

            fetch(url, {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                }
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error('Network response was not ok');
                }
                return response.text();
            })
            .then(data => {
                updateStatus(action, data);
            })
            .catch(error => {
                console.error('There was a problem with the fetch operation:', error);
                showAlert('Error: ' + error.message, true);
            });
        });
    </script>
</body>
</html>