@model DatabasesModel
@{
    Layout = "Databases.Modal.cshtml";
    var s = Model.Instance;
    var backups = s.GetBackupInfo(Model.Database);
}
@section top {
    <span class="pull-right small">@Poll.Now(backups)</span>
}
@if (backups.Data == null || !backups.Successful)
{
    <div class="alert alert-warning">
        <h5>There was an error fetching table info from @s.Name for @Model.Database</h5>
        <p class="error-stack">@backups.ErrorMessage</p>
    </div>
}
else {
    <table class="table table-striped table-hover text-nowrap table-super-condensed table-responsive js-database-backups">
        <thead>
            <tr>
                <th>Type</th>
                <th>Start</th>
                <th>Finish</th>
                <th>Size <span class="text-muted">(Compressed)</span></th>
                <th>Media</th>
                <th>Location</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var b in backups.Data.OrderByDescending(b => b.FinishDate))
            {
                <tr class="@(b.TypeDescription == "Full" ? "info" : null)">
                    <td>@b.TypeDescription</td>
                    <td>@(b.StartDate?.ToRelativeTimeSpanMini())</td>
                    <td>@(b.FinishDate?.ToRelativeTimeSpanMini())</td>
                    <td>@(b.SizeBytes?.ToSize()) <span class="text-muted">(@(b.CompressedSizeBytes?.ToSize()))</span></td>
                    <td>@(b.MediaDeviceType.HasValue ? b.MediaDeviceType.Value.AsString(EnumFormat.Description) : "")</td>
                    <td title="@(b.PhysicalDeviceName ?? b.LogicalDeviceName)">@((b.PhysicalDeviceName ?? b.LogicalDeviceName).TruncateWithEllipsis(75))</td>
                </tr>
            }
        </tbody>
        <tfoot>
            @if (!backups.Data.Any())
            {
                <tr>
                    <td colspan="6">
                        <div class="no-content">There aren't any backups in available history.</div>
                    </td>
                </tr>
            }
        </tfoot>
    </table>
    <script>
        $(function () {
            $('.js-database-backups').tablesorter({
                headers: {
                    1: { sorter: 'dataVal', sortInitialOrder: 'desc' },
                    2: { sorter: 'dataVal', sortInitialOrder: 'desc' },
                    3: { sorter: 'dataVal', sortInitialOrder: 'desc' },
                    4: { sorter: 'dataVal', sortInitialOrder: 'desc' },
                    5: { sorter: 'dataVal', sortInitialOrder: 'desc' },
                    6: { sorter: 'dataVal', sortInitialOrder: 'desc' }
                }
            });
        });
    </script>
}