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

<div class="flex items-center justify-between mb-6">
    <h1 class="text-2xl font-bold">Serverübersicht</h1>
    <a asp-controller="Server" asp-action="AddServer"
        class="bg-blue-600 text-white px-4 py-2 rounded hover:bg-blue-700">
        + 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-4 border border-gray-200">
            <div class="flex justify-between items-start">
                <div>
                    <h2 class="text-lg font-semibold">(#@s.Id) @s.Name</h2>
                </div>
                <span class="text-sm px-2 py-1 rounded 
                    @(s.IsOnline ? "bg-green-100 text-green-700" : "bg-red-100 text-red-700")">
                    @(s.IsOnline ? "Online" : "Offline")
                </span>
            </div>

            <div class="mt-4 text-sm space-y-1 text-gray-700">
                <div><strong>IP:</strong> @s.IPAddress</div>
                <div><strong>Typ:</strong> @s.Type</div>
                <div><strong>Status:</strong> @((s.IsOnline) ? "Online" : "Offline")</div>
                <div><strong>Erstellt:</strong> @s.CreatedAt.ToLocalTime().ToString("dd.MM.yyyy HH:mm")</div>
                <div><strong>Last-Seen:</strong> @(s.LastSeen.ToLocalTime().ToString("dd.MM.yyyy HH:mm") ?? "Never")</div>
            </div>

            <div class="mt-4 flex justify-end gap-2">
                <a asp-action="EditServer" asp-route-id="@s.Id" class="btn btn-sm btn-primary">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-semibold">Löschen</button>
                </form>
            </div>
        </div>
    }
</div>