@using ZelWiki.Models
@model ZelWiki.Models.ViewModels.Admin.DatabaseViewModel
@{
    Layout = "/Views/Shared/_Layout.cshtml";
    var sessionState = ViewData["SessionState"] as ZelWiki.SessionState ?? throw new Exception("Wiki State Context cannot be null.");
}

<h3>
    数据库
</h3>

<p>
</p>

@if (!string.IsNullOrEmpty(Model.ErrorMessage))
{
    <div class="alert alert-danger">@Html.Raw(Model.ErrorMessage)</div>
}
@if (!string.IsNullOrEmpty(Model.SuccessMessage))
{
    <div class="alert alert-success">@Html.Raw(Model.SuccessMessage)</div>
}

@using (Html.BeginForm(null, null, FormMethod.Get, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
{
    <table class="table fixedTable100 table-striped" border="0" width="100%" cellspacing="0" cellpadding="0">
        <thead>
            <tr>
                <td><strong>Name</strong></td>
                <td><strong>Version</strong></td>
                <td><strong>Size</strong></td>
                <td><strong>Action</strong></td>
            </tr>
        </thead>

        @foreach (var info in Model.Info)
        {
            <tr>
                <td>@info.Name</td>
                <td>@info.Version</td>
                <td>@NTDLS.Helpers.Formatters.FileSize((long)info.DatabaseSize)</td>
                <td>
                    @Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateSafeLink(GlobalConfiguration.BasePath, 
                        "即将优化数据库索引和结构,继续?",
                        "优化", $"/Admin/Database/Optimize/{info.Name}", Context.Request.Path.Value))
                    @Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateSafeLink(GlobalConfiguration.BasePath,
                        "即将从数据库中删除空白空间，如果删除了大量数据，则可以释放空间,继续吗?",
                        "真空化", $"/Admin/Database/Vacuum/{info.Name}", Context.Request.Path.Value))
                    @Html.Raw(ZelWiki.Library.ConfirmActionHelper.GenerateSafeLink(GlobalConfiguration.BasePath,
                        "即将检查数据库的完整性并验证所有外键,继续吗?",
                        "校验", $"/Admin/Database/Verify/{info.Name}", Context.Request.Path.Value))
                </td>
            </tr>
        }
    </table>
}
