{% if session['theme'] == 'darkmode' %}
    {% extends "base_dark.html" %}
{% else %}
    {% extends "base.html" %}
{% endif %}

{% block title %}IP Checker{% endblock %}

{% block content %}
<div class="content-wrapper">
    <div class="form-container" style="max-width: {% if session['theme'] == 'darkmode' %}1000px{% else %}800px{% endif %}; padding: 30px; max-height: 90vh; overflow-y: auto;">
        <h2>IP Checker</h2>
        <form method="POST">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
            <input type="text" name="ip_address" placeholder="IP-Adresse eingeben" required>
            <br>
            <label for="is_cheater">Ist diese IP eines Cheaters?</label>
            <div class="styled-select">
                <select name="is_cheater" id="is_cheater" required>
                    <option value="no">Nein</option>
                    <option value="yes">Ja</option>
                </select>
            </div>
            <br>
            <input type="text" name="steam_id" id="steam_id" placeholder="SteamID (erforderlich für Cheater)">
            <br>
            <div style="display: flex; gap: 20px">
                {% if session['theme'] == 'darkmode' %}
                    <button type="submit" class="neon-button neon1" style="flex: 1;"><span>Prüfen</span></button>
                    <a href="/dashboard" class="neon-button neon3" style="flex: 1; text-align: center;"><span>Zurück</span></a>
                {% else %}
                    <button type="submit" style="flex: 1; padding: 10px;">Prüfen</button>
                    <a href="/dashboard" class="black-button" style="flex: 1; padding: 10px; text-align: center;">Zurück</a>
                {% endif %}
            </div>
        </form>

        {% if error %}
            <p style="color: red; margin-top: 20px;">{{ error }}</p>
        {% endif %}
        {% if ip_data %}
            <h3 style="margin-top: 30px;">IP-Daten</h3>
            <table style="width: 100%; border-collapse: collapse; margin-top: 20px;">
                <tr>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">Feld</th>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">Wert</th>
                </tr>
                <tr><td style="padding: 10px; border: 1px solid #ddd;">IP-Adresse</td><td style="padding: 10px; border: 1px solid #ddd;">{{ ip_data.get('ip', 'N/A') }}</td></tr>
                <tr><td style="padding: 10px; border: 1px solid #ddd;">VPN</td><td style="padding: 10px; border: 1px solid #ddd;">{{ 'Ja' if ip_data['security'].get('vpn', False) else 'Nein' }}</td></tr>
                <tr><td style="padding: 10px; border: 1px solid #ddd;">Proxy</td><td style="padding: 10px; border: 1px solid #ddd;">{{ 'Ja' if ip_data['security'].get('proxy', False) else 'Nein' }}</td></tr>
                <tr><td style="padding: 10px; border: 1px solid #ddd;">Tor</td><td style="padding: 10px; border: 1px solid #ddd;">{{ 'Ja' if ip_data['security'].get('tor', False) else 'Nein' }}</td></tr>
                <tr><td style="padding: 10px; border: 1px solid #ddd;">Land</td><td style="padding: 10px; border: 1px solid #ddd;">{{ ip_data['location'].get('country', 'N/A') }}</td></tr>
                <tr><td style="padding: 10px; border: 1px solid #ddd;">Stadt</td><td style="padding: 10px; border: 1px solid #ddd;">{{ ip_data['location'].get('city', 'N/A') }}</td></tr>
                <tr><td style="padding: 10px; border: 1px solid #ddd;">ASN</td><td style="padding: 10px; border: 1px solid #ddd;">{{ ip_data['network'].get('autonomous_system_number', 'N/A') }}</td></tr>
                <tr><td style="padding: 10px; border: 1px solid #ddd;">Netzwerk</td><td style="padding: 10px; border: 1px solid #ddd;">{{ ip_data['network'].get('network', 'N/A') }}</td></tr>
            </table>
        {% endif %}
        {% if similar_cheater_ips %}
            <h3 style="margin-top: 30px;">Ähnliche Cheater-IPs</h3>
            <table style="width: 100%; border-collapse: collapse; margin-top: 20px;">
                <tr>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">IP-Adresse</th>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">Stadt</th>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">ASN</th>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">SteamID</th>
                </tr>
                {% for ip in similar_cheater_ips %}
                    <tr>
                        <td style="padding: 10px; border: 1px solid #ddd;">{{ ip['ip'] }}</td>
                        <td style="padding: 10px; border: 1px solid #ddd;">{{ ip['data']['location'].get('city', 'N/A') }}</td>
                        <td style="padding: 10px; border: 1px solid #ddd;">{{ ip['data']['network'].get('autonomous_system_number', 'N/A') }}</td>
                        <td style="padding: 10px; border: 1px solid #ddd;">{{ ip.get('steam_id', 'N/A') }}</td>
                    </tr>
                {% endfor %}
            </table>
        {% endif %}
        {% if similar_ips|selectattr('is_cheater', 'equalto', True)|list|length > 0 %}
            <h3 style="margin-top: 30px;">Ähnliche Cheater-IPs</h3>
            <table style="width: 100%; border-collapse: collapse; margin-top: 20px;">
                <tr>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">IP-Adresse</th>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">Stadt</th>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">ASN</th>
                    <th style="padding: 10px; border: 1px solid #ddd; background-color: #007BFF; color: white;">SteamID</th>
                </tr>
                {% for ip in similar_ips %}
                    {% if ip['is_cheater'] %}
                    <tr>
                        <td style="padding: 10px; border: 1px solid #ddd;">{{ ip['ip'] }}</td>
                        <td style="padding: 10px; border: 1px solid #ddd;">{{ ip['data']['location'].get('city', 'N/A') }}</td>
                        <td style="padding: 10px; border: 1px solid #ddd;">{{ ip['data']['network'].get('autonomous_system_number', 'N/A') }}</td>
                        <td style="padding: 10px; border: 1px solid #ddd;">{{ ip.get('steam_id', 'N/A') }}</td>
                    </tr>
                    {% endif %}
                {% endfor %}
            </table>
        {% endif %}
    </div>
</div>
{% endblock %}
