@model Watcher.ViewModels.ServerOverviewViewModel
@{
    ViewData["Title"] = "Serverübersicht";
}

<div class="flex items-center justify-between mb-6">
    <h1 class="text-2xl font-bold">
        <i class="bi bi-hdd-network me-2 text-blue-700"></i>Serverübersicht
    </h1>
    <a asp-controller="Server" asp-action="AddServer"
        class="bg-blue-600 hover:bg-blue-700 text-white font-medium py-2 px-4 rounded transition">
        <i class="bi bi-plus-circle me-1"></i>Server hinzufügen
    </a>
</div>

<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
    @foreach (var s in Model.Servers)
    {
        <div class="bg-white rounded-xl shadow p-5 border border-gray-200 flex flex-col gap-4">
            <div class="flex justify-between items-center">
                <h2 class="text-lg font-semibold text-gray-800">
                    <i class="bi bi-cpu me-1 text-gray-600"></i>(#@s.Id) @s.Name
                </h2>
                <span class="text-sm px-2 py-1 rounded font-medium
                        @(s.IsOnline ? "bg-green-100 text-green-700" : "bg-red-100 text-red-700")">
                    <i class="bi @(s.IsOnline ? "bi-check-circle" : "bi-x-circle") me-1"></i>
                    @(s.IsOnline ? "Online" : "Offline")
                </span>
            </div>

            <div class="flex gap-6">
                <!-- Linke Seite: Infos, nimmt ca. 40% Breite -->
                <div class="flex-1 max-w-[40%] text-sm space-y-1 text-gray-700">
                    <div><i class="bi bi-globe me-1 text-gray-500"></i><strong>IP:</strong> @s.IPAddress</div>
                    <div><i class="bi bi-hdd me-1 text-gray-500"></i><strong>Typ:</strong> @s.Type</div>
                    <div><i class="bi bi-calendar-check me-1 text-gray-500"></i><strong>Erstellt:</strong>
                        @s.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy HH:mm")</div>
                    <div><i class="bi bi-clock me-1 text-gray-500"></i><strong>Last-Seen:</strong>
                        @s.LastSeen.ToLocalTime().ToString("dd.MM.yyyy HH:mm")</div>
                </div>

                <!-- Rechte Seite: Zwei Diagramme nebeneinander, je ca. 50% von 60% = 30% insgesamt -->
                <div class="flex-1 flex gap-4 max-w-[60%]">
                    

                </div>
            </div>

            <div class="flex justify-end gap-3">
                <a asp-action="EditServer" asp-route-id="@s.Id" class="text-blue-600 hover:text-blue-800 font-medium">
                    <i class="bi bi-pencil-square me-1"></i>Bearbeiten
                </a>

                <form asp-action="Delete" asp-route-id="@s.Id" method="post"
                    onsubmit="return confirm('Diesen Server wirklich löschen?');">
                    <button type="submit" class="text-red-600 hover:text-red-800 font-medium">
                        <i class="bi bi-trash me-1"></i>Löschen
                    </button>
                </form>
            </div>
        </div>
    }
</div>

<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>

@section Scripts {
<script>
    document.addEventListener("DOMContentLoaded", function () {
        @foreach (var s in Model.Servers)
        {
            <text>
            var ctxCpu_@s.Id = document.getElementById("cpuChart-@s.Id").getContext('2d');
            var cpuChart_@s.Id = new Chart(ctxCpu_@s.Id, {
                type: 'bar',
                data: {
                    labels: ['0s', '5s', '10s', '15s', '20s'],
                    datasets: [{
                        label: 'CPU %',
                        data: [12, 19, 7, 15, 10], // Beispielwerte
                        backgroundColor: 'rgba(59, 130, 246, 0.7)', // Tailwind blue-500 transparent
                        borderColor: 'rgba(59, 130, 246, 1)',
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    animation: false,
                    scales: {
                        y: {
                            beginAtZero: true,
                            max: 100
                        }
                    },
                    plugins: {
                        legend: {
                            display: false
                        }
                    }
                }
            });

            var ctxRam_@s.Id = document.getElementById("ramChart-@s.Id").getContext('2d');
            var ramChart_@s.Id = new Chart(ctxRam_@s.Id, {
                type: 'bar',
                data: {
                    labels: ['0s', '5s', '10s', '15s', '20s'],
                    datasets: [{
                        label: 'RAM %',
                        data: [45, 40, 55, 48, 50], // Beispielwerte
                        backgroundColor: 'rgba(16, 185, 129, 0.7)', // Tailwind green-500 transparent
                        borderColor: 'rgba(16, 185, 129, 1)',
                        borderWidth: 1
                    }]
                },
                options: {
                    responsive: true,
                    animation: false,
                    scales: {
                        y: {
                            beginAtZero: true,
                            max: 100
                        }
                    },
                    plugins: {
                        legend: {
                            display: false
                        }
                    }
                }
            });
            </text>
        }
    });
</script>
}

