<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BingerVPN Dashboard</title>

<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css"/>

<style>
    body {
        margin: 0;
        font-family: Arial, sans-serif;
        background: #d9d9dc;
    }

    /* TOP NAV */
    .navigationbar {
        background: #1e1e21;
        color: white;
        padding: 20px 40px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .vpn_name {
        font-size: 2.2rem;
        font-weight: bold;
    }

    .container {
        width: 96%;
        margin: 20px auto;
    }

    /* SECTION HEADER */
    .section-title {
        background: #505050;
        color: white;
        text-align: center;
        font-size: 2rem;
        padding: 12px;
        font-weight: bold;
    }

    /* SERVER TABLE */
    .server-table,
    .client-table {
        width: 100%;
        border-collapse: collapse;
    }

    .server-wrapper,
    .client-wrapper {
        background: #bcbec2;
        padding: 20px;
    }

    .server-table th {
        text-align: left;
        font-size: 1.5rem;
        padding-bottom: 10px;
        border-bottom: 2px solid #555;
    }

    .server-table td {
        font-size: 1.4rem;
        padding-top: 12px;
    }

    /* CLIENT TABLE */
    .client-table {
        margin-top: 20px;
    }

    .client-table th {
        background: #f2f2f2;
        padding: 14px;
        border-right: 1px solid #444;
        font-size: 1.1rem;
    }

    .client-table td {
        padding: 14px;
        text-align: center;
        border-right: 1px solid #444;
    }

    .client-table tr:nth-child(even) {
        background: #d9d9d9;
    }

    .client-table tr:nth-child(odd) {
        background: #c4c4c4;
    }

    .map-placeholder {
        margin-top: 35px;
        background: #505050;
        color: white;
        text-align: center;
        font-size: 2rem;
        padding: 12px;
        font-weight: bold;
    }

    .map-container {
   	width: 70%;
   	margin: 20px auto;
    }

    #map {
    	height: 300px;
    	width: 100%;
    }

</style>
</head>
<body>

<div class="navigationbar">
    <div class="vpn_name">BingerVPN</div>
</div>

<div class="container">

    <div class="section-title">Client VPN</div>

    <div class="server-wrapper">
        <table class="server-table">
            <tr>
                <th>VPN Mode</th>
                <th>Status</th>
                <th>Clients</th>
                <th>Up Since</th>
                <th>Server IP</th>
            </tr>
            <tr>
                <td>Server</td>
                <td style="color: green; font-weight: bold;">CONNECTED</td>
                <td>{{ clients|length }}</td>
                <td>{{ uptime }}</td>
                <td>{{ server_ip }}</td>
            </tr>
        </table>

        <table class="client-table">
            <tr>
                <th>Username</th>
                <th>VPN IP Address</th>
                <th>Remote IP Address</th>
                <th>Bytes In</th>
                <th>Bytes Out</th>
                <th>Connected Since</th>
                <th>Cipher</th>
            </tr>

            {% for client in clients %}
            <tr>
                <td>{{ client.NAME }}</td>
                <td>{{ client.VPN_IP_ADDRESS }}</td>
                <td>{{ client.CLIENT_REAL_ADDRESS }}</td>
                <td>{{ client.BYTES_IN }}</td>
                <td>{{ client.BYTES_OUT }}</td>
                <td>{{ client.CONNECTED_SINCE }}</td>
                <td>{{ client.CIPHER }}</td>
            </tr>
            {% endfor %}
        </table>
    </div>

    <div class="map-placeholder">Map View</div>
    
    <div class="map-container">
    	<div id="map"></div>
    </div>

</div>

<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
<script>
    const serverLat = {{ server_latitude }};
    const serverLon = {{ server_longitude }};
    const serverLocationName = "{{ server_city }}";
    const serverIp = "{{ server_ip }}";

    const map = L.map('map').setView([serverLat, serverLon], 10);

    L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
        attribution: '&copy; OpenStreetMap contributors'
    }).addTo(map);

    L.marker([serverLat, serverLon])
        .addTo(map)
        .bindPopup(`<b>BingerVPN Server</b><br>${serverLocationName}<br>${serverIp}`)
        .openPopup();
</script>	

</body>
</html>
