<!DOCTYPE html>
<html lang="de">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Daten anzeigen</title>
    <link rel="stylesheet" href="/static/style.css">
    <link rel="icon" href="/static/logo.png" type="image/png">
    <style>
        body {
            background-image: url('/static/background.png');
            background-size: cover;
            background-position: center;
            background-repeat: no-repeat;
            height: 100vh;
            margin: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            overflow: hidden;
        }
        .content {
            background: rgba(255, 255, 255, 0.8);
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            width: 80%;
            max-width: 800px;
            max-height: 90vh;
            overflow-y: auto;
            text-align: center;
        }
        .content h2 {
            text-align: center;
        }
        .content form {
            display: flex;
            flex-direction: column;
            align-items: center;
        }
        .content form label {
            margin-top: 10px;
            width: 100%;
            text-align: left;
        }
        .content form input,
        .content form textarea,
        .content form select {
            width: 100%;
            padding: 10px;
            margin-top: 5px;
            border: 1px solid #ccc;
            border-radius: 4px;
        }
        .content form button {
            background-color: #007BFF;
            color: white;
            border: none;
            padding: 10px 15px;
            cursor: pointer;
            border-radius: 4px;
            margin-top: 20px;
        }
        .content form button:hover {
            background-color: #0056b3;
        }
        .search-bar {
            display: flex;
            align-items: center;
            margin-bottom: 20px;
        }
        .search-bar input {
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            margin-right: 10px;
        }
        .search-bar button {
            background-color: #007BFF;
            color: white;
            border: none;
            padding: 10px 15px;
            cursor: pointer;
            border-radius: 4px;
        }
        .search-bar button:hover {
            background-color: #0056b3;
        }
        .message {
            display: none;
            color: red;
            margin-top: 10px;
        }
    </style>
</head>
<body>
    {% include "top_bar.html" %}
    <div class="content">
        <h2>Daten aus der MongoDB</h2>
        <div class="search-bar">
            <input type="text" id="licenseKeyInput" placeholder="License Key einfügen">
            <button onclick="searchLicenseKey()">Suchen</button>
        </div>
        <div class="message" id="message">
            <img src="/static/red_cross.png" alt="Cross" style="width: 20px; vertical-align: middle;">
            Der License Key wurde nicht gefunden
        </div>
        {% for doc in data %}
            <form action="{{ url_for('view_license', license_key=doc['license_key']) }}" method="get">
                <button type="submit">{{ doc['ingame_name'] }}</button>
            </form>
        {% endfor %}
        <a href="/license_keys" class="black-button" style="margin-top: 20px;">Zurück</a>
    </div>
    <script>
        function searchLicenseKey() {
            var licenseKey = document.getElementById("licenseKeyInput").value;
            fetch(`/search_license_key?license_key=${licenseKey}`)
                .then(response => response.json())
                .then(data => {
                    if (data.found) {
                        window.location.href = `/license=${licenseKey}`;
                    } else {
                        var message = document.getElementById("message");
                        message.style.display = "block";
                        setTimeout(function() {
                            message.style.display = "none";
                        }, 2000);
                    }
                });
        }
    </script>
</body>
</html>
