@model LogsModel
@{
    ViewData["Title"] = "Logs";
}

<h1>Logs</h1>

<p>Current UTC time: @DateTime.UtcNow.ToString()</p>

<form class="form-inline mb-2" method="get">
    <label class="sr-only" asp-for="Level">Level</label>
    <select class="form-control mb-2 mr-2" asp-for="Level" name="level"
            asp-items="Html.GetEnumSelectList<Serilog.Events.LogEventLevel>()">
        <option value="">-- Level --</option>
    </select>
    <label class="sr-only" asp-for="Project">Project</label>
    <select class="form-control mb-2 mr-2" asp-for="Project" name="project">
        <option asp-selected="string.IsNullOrWhiteSpace(Model.Project)" value="">-- Project --</option>
        <option asp-selected="@(Model.Project == "Admin")" value="Admin">Admin</option>
        <option asp-selected="@(Model.Project == "Api")" value="Api">Api</option>
        <option asp-selected="@(Model.Project == "Billing")" value="Billing">Billing</option>
        <option asp-selected="@(Model.Project == "Events")" value="Events">Events</option>
        <option asp-selected="@(Model.Project == "Events Processor")" value="Events Processor">Events Processor</option>
        <option asp-selected="@(Model.Project == "Identity")" value="Identity">Identity</option>
        <option asp-selected="@(Model.Project == "Notifications")" value="Notifications">Notifications</option>
        <option asp-selected="@(Model.Project == "Icons")" value="Icons">Icons</option>
        <option asp-selected="@(Model.Project == "Business Portal")" value="Business Portal">Business Portal</option>
        <option asp-selected="@(Model.Project == "SSO")" value="SSO">SSO</option>
    </select>
    <input class="form-control mb-2 mr-2" type="datetime-local" asp-for="Start" name="start" placeholder="Start Date">
    <input class="form-control mb-2 mr-2" type="datetime-local" asp-for="End" name="end" placeholder="End Date">
    <button type="submit" class="btn btn-primary mb-2" title="Search"><i class="fa fa-search"></i> Search</button>
</form>

<div class="table-responsive">
    <table class="table table-striped table-hover">
        <thead>
            <tr>
                <th style="width: 50px;">&nbsp;</th>
                <th style="width: 210px;">Timestamp</th>
                <th style="width: 105px;">Project</th>
                <th style="width: 125px;">Level</th>
                <th>Message</th>
            </tr>
        </thead>
        <tbody>
            @if(!Model.Items.Any())
            {
                <tr>
                    <td colspan="5">No results to list.</td>
                </tr>
            }
            else
            {
                @foreach(var log in Model.Items)
                {
                    <tr>
                        <td>
                            <a asp-action="View" asp-route-id="@log.Id" title="View">
                                <i class="fa fa-file-text-o fa-lg"></i>
                            </a>
                        </td>
                        <td>@log.Timestamp.ToString()</td>
                        <td>@(string.IsNullOrWhiteSpace(log.Project) ? "-" : log.Project)</td>
                        <td>@log.Level</td>
                        <td>@log.MessageTruncated</td>
                    </tr>
                }
            }
        </tbody>
    </table>
</div>

<nav>
    <ul class="pagination">
        @if(string.IsNullOrWhiteSpace(Model.NextCursor))
        {
            <li class="page-item disabled">
                <a class="page-link" href="#" tabindex="-1">Next</a>
            </li>
        }
        else
        {
            <li class="page-item">
                <a class="page-link" asp-action="Index" asp-route-cursor="@Model.NextCursor"
                   asp-route-count="@Model.Count" asp-route-project="@Model.Project"
                   asp-route-level="@Model.Level">Next</a>
            </li>
        }
    </ul>
</nav>
