@model TightWiki.Models.ViewModels.Admin.EmojisViewModel
@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>
    Emojis
</h3>

<p>
    Global configuration for Emojis.<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/AddEmoji">Add new emoji</a>
<br />
<br />

@using (Html.BeginForm(null, null, FormMethod.Get, new { action = $"{GlobalConfiguration.BasePath}{Context.Request.Path}" }))
{
    <div class="container">
        <div class="d-flex justify-content-end mb-4">
            <div class="flex-grow-1 me-2">
                @Html.TextBoxFor(x => x.SearchString, new { @class = "form-control" })
            </div>
            <button type="submit" class="btn btn-primary">Search</button>
        </div>
    </div>
    <br />

    @if (Model.Emojis.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, "Shortcut")">Shortcut</a></strong></td>
                    <td><strong>Image</strong></td>
                </tr>
            </thead>

            @foreach (var emoji in Model.Emojis)
            {
                <tr>
                    <td><a href="@GlobalConfiguration.BasePath/Admin/Emoji/@emoji.Name">@emoji.Name</a></td>
                    <td>@emoji.Shortcut</td>
                    <td><img src="@GlobalConfiguration.BasePath/File/Emoji/@emoji.Name" alt="@emoji.Name" /></td>
                </tr>
            }
        </table>

        @Html.Raw(TightWiki.Library.PageSelectorGenerator.Generate(Context.Request.QueryString, Model.PaginationPageCount))
    }
    else
    {
        <div class="d-flex small text-muted mb-0">
            <strong>
                Either there are no emojis configured or your search criteria returned no results.
            </strong>
        </div>
    }
}

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

<script>
    window.onload = function () {
        document.getElementById("SearchString").focus();
    }
</script>
