PAGE_TEMPLATE = """
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.0/socket.io.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 0;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            overflow: hidden;
            text-align: center;
            position: relative;
            background-color: black; 
        }
        body::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: url('{{ url_for('static', filename='boost_bot_v2.gif') }}') center center / cover no-repeat;
            filter: blur(10px); 
            z-index: -1; 
        }
        header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: black;
            color: white;
            padding: 10px 20px;
            width: 100%;
            position: absolute;
            top: 0;
            left: 0;
            box-sizing: border-box;
            z-index: 1;
        }
        header img {
            height: 40px;
        }
        header a {
            text-decoration: none;
        }
        header button {
            background-color: white;
            color: black;
            border: none;
            padding: 8px 15px;
            border-radius: 5px;
            cursor: pointer;
            font-size: 14px;
        }
        header button:hover {
            background-color: #0056b3;
            color: white;
        }
        .license-info-box {
            text-align: center;
            padding: 20px;
            background-color: rgba(0, 0, 0, 0.9);
            border-radius: 10px;
            box-shadow: 0 0 15px 5px cyan;
            max-width: 600px;
            width: 90%;
            margin-top: 80px;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            z-index: 1;
        }
        .license-info-box h1 {
            font-size: 20px;
            margin-bottom: 15px;
            color: cyan;
        }
        .license-info-box p {
            font-size: 16px;
            margin: 5px 0;
        }
        .license-info-box p strong {
            color: #00FFFF;
        }
        .month-info-container {
            display: flex;
            justify-content: space-around;
            width: 100%;
            margin-top: 20px;
        }
        .month-info {
            margin: 10px;
            padding: 15px;
            border-radius: 10px;
            background-color: rgba(255, 255, 255, 0.1);
            border: 2px solid white;
            width: 40%;
            text-align: center;
            box-shadow: 0 0 10px 2px white;
        }
        .month-info h2 {
            font-size: 18px;
            margin-bottom: 10px;
            color: cyan;
        }
        .month-info p {
            margin: 5px 0;
            font-size: 14px;
        }
        .last-updated {
            margin-top: 20px;
            font-size: 14px;
            color: gray;
        }
    </style>
</head>
<body>
    <header>
        <img src="{{ url_for('static', filename='logo.gif') }}" alt="Logo">
        <a href="https://S2Tools.mysellix.io/group/66c98ff2386f1" target="_blank">
            <button>Buy Here</button>
        </a>
    </header>
    <div class="license-info-box">
        <h1>Stock Data</h1>

        <!-- Stock Information -->
        <div class="month-info-container">
            <div class="month-info">
                <h2>3 Month Stock</h2>
                <p><strong>Boosts:</strong> {{ three_month_boosts }}</p>
                <p><strong>Tokens:</strong> {{ three_month_tokens }}</p>
            </div>
            <div class="month-info">
                <h2>1 Month Stock</h2>
                <p><strong>Boosts:</strong> {{ one_month_boosts }}</p>
                <p><strong>Tokens:</strong> {{ one_month_tokens }}</p>
            </div>
        </div>

        <p class="last-updated"><strong>Last Updated:</strong> <span id="last-updated"></span></p>
    </div>

    <script>
        let lastUpdatedTimestamp = {{ last_updated }};
        const lastUpdatedElement = document.getElementById('last-updated');
        function updateLastUpdated() {
            const now = Math.floor(Date.now() / 1000);
            const elapsed = now - lastUpdatedTimestamp;

            const days = Math.floor(elapsed / (24 * 60 * 60));
            const hours = Math.floor((elapsed % (24 * 60 * 60)) / (60 * 60));
            const minutes = Math.floor((elapsed % (60 * 60)) / 60);
            const seconds = elapsed % 60;

            let timeString = '';
            if (days > 0) timeString += `${days}d `;
            if (hours > 0 || days > 0) timeString += `${hours}h `;
            if (minutes > 0 || hours > 0 || days > 0) timeString += `${minutes}m `;
            timeString += `${seconds}s`;

            if (elapsed > (5 * 60)) { 
                timeString = "Bot Offline";
                lastUpdatedElement.style.color = "red";
            } else {
                lastUpdatedElement.style.color = ""; 
            }

            lastUpdatedElement.textContent = timeString;
        }

        updateLastUpdated();
        setInterval(updateLastUpdated, 1000);

        var socket = io.connect('http://' + document.domain + ':' + location.port);

        socket.on('connect', function() {
            console.log('SocketIO connected!');
        });
        socket.on('update_stock_data', function(data) {
        if (data.unique_id === "{{ unique_id }}") {
            document.querySelector('.month-info-container').innerHTML = `
                <div class="month-info">
                    <h2>3 Month Stock</h2>
                    <p><strong>Boosts:</strong> ${data.three_month_boosts}</p>
                    <p><strong>Tokens:</strong> ${data.three_month_tokens}</p>
                </div>
                <div class="month-info">
                    <h2>1 Month Stock</h2>
                    <p><strong>Boosts:</strong> ${data.one_month_boosts}</p>
                    <p><strong>Tokens:</strong> ${data.one_month_tokens}</p>
                </div>
            `;

            lastUpdatedTimestamp = data.last_updated
            console.log('Updated Stock')
            } else {
                console.log('Meant for another user')
            }
        });
    </script>
</body>
</html>
"""