@model List<Watcher.Controllers.DatabaseController.DumpFileInfo>
@{
    ViewData["Title"] = "Datenbank-Dumps";
}

<head>
    <link rel="stylesheet" href="~/css/main.css" />
    <link rel="stylesheet" href="~/css/databases.css" />
</head>

<h2 class="mb-4 text-xl font-bold"><i class="bi bi-hdd me-1"></i>Datenbank-Dumps</h2>

@if (TempData["Success"] != null)
{
    <div class="alert alert-success">@TempData["Success"]</div>
}
@if (TempData["Error"] != null)
{
    <div class="alert alert-danger">@TempData["Error"]</div>
}

<table class="dumptable">
    <thead>
        <tr>
            <th>Dateiname</th>
            <th>Größe (KB)</th>
            <th>Erstellt</th>
            <th>Aktionen</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var dump in Model)
        {
            <tr>
                <td>@dump.FileName</td>
                <td>@dump.SizeKb</td>
                <td>@dump.Created.ToString("dd.MM.yyyy HH:mm")</td>
                <td class="d-flex gap-2">
                    <a class="btn btn-outline-primary btn-sm"
                       href="@Url.Action("FileDownload", "Download", new { type= "sqlite", fileName = dump.FileName })">
                        <i class="bi bi-download me-1"></i>Download
                    </a>

                    <form method="post" asp-action="Delete" asp-controller="Database" asp-route-fileName="@dump.FileName" onsubmit="return confirm('Diesen Dump wirklich löschen?');">
                        <button type="submit" class="btn btn-outline-danger btn-sm">
                            <i class="bi bi-trash me-1"></i>Löschen
                        </button>
                    </form>

                    <form method="post" asp-action="Restore" asp-controller="Database" asp-route-fileName="@dump.FileName" onsubmit="return confirm('Achtung! Der aktuelle DB-Stand wird überschrieben. Fortfahren?');">
                        <button type="submit" class="btn btn-outline-warning btn-sm">
                            <i class="bi bi-arrow-clockwise me-1"></i>Wiederherstellen
                        </button>
                    </form>
                </td>
            </tr>
        }
    </tbody>
</table>
