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

<h3>
    Site Menu Items
</h3>

<p>
    Global configuration for the site menu.<br /><br />
</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>
}

<a class="btn btn-success btn-thin" href="@GlobalConfiguration.BasePath/Admin/MenuItem">Add new item</a>
<br />
<br />

@using (Html.BeginForm(null, null, FormMethod.Post, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
{
    @Html.AntiForgeryToken()

    @if (Model.Items.Count > 0)
    {
        <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
            <thead>
                <tr>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Name")">Name</a></strong></td>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Link")">Link</a></strong></td>
                    <td><strong><a href="?@QueryStringConverter.OrderHelper(sessionState, "Ordinal")">Ordinal</a></strong></td>
                </tr>
            </thead>

            @foreach (var item in Model.Items)
            {
                <tr>
                    <td><a href="@GlobalConfiguration.BasePath/Admin/MenuItem/@item.Id">@item.Name</a></td>
                    <td>@item.Link</td>
                    <td>@item.Ordinal</td>
                </tr>
            }
        </table>
    }
    else
    {
        <div class="d-flex small text-muted mb-0">
            <strong>
                Their are no menu items configured.
            </strong>
        </div>
    }
}

<br />
<a class="btn btn-success btn-thin" href="@GlobalConfiguration.BasePath/Admin/MenuItem">Add new item</a>
