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

<h3>
    搜索
</h3>

<p>
    找找有没有你想要的<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>
}

@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", style = "width:100%" })
            </div>
            <button type="submit" value="Find" class="btn btn-primary">搜一搜</button>
        </div>
    </div>
    <br />

    <table class="table fixedTable100 table-striped" border="0" cellspacing="0" cellpadding="0">
        @foreach (var p in Model.Pages)
        {
            <tr>
                <td>
                    @if ((p.Namespace ?? "") != "")
                    {
                        <font class="text-muted">@p.Namespace ::</font>
                    }<a href="@GlobalConfiguration.BasePath/@p.Navigation">@p.Title</a>@(String.IsNullOrEmpty(@p.Description) ? "" : " : ")  @p.Description
                </td>
            </tr>
        }
    </table>

    if (Model.Pages.Count == 0)
    {
        <div class="d-flex small text-muted mb-0">
            <strong>
                好像啥也没查到哎
            </strong>
        </div>
    }

    @Html.Raw(TightWiki.Library.PageSelectorGenerator.Generate(Context.Request.QueryString, Model.PaginationPageCount))
}

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