@using System.Linq
@using MrCMS.Entities.Documents.Web
@using MrCMS.Helpers
@using MrCMS.Models
@using MrCMS.Paging
@using MrCMS.Web.Apps.Core.Models.Search
@using MrCMS.Web.Apps.Core.Pages
@model MrCMS.Web.Apps.Core.Pages.SearchPage
@{
    var searchModel = ViewData["webpageSearchQueryModel"] as WebpageSearchQuery;
    var results = ViewData["searchResults"] as IPagedList<Webpage>;
}
@Editable(Model, page => page.BodyContent, true)
@{Html.RenderPartial("SearchQuery", searchModel);}
<p></p>
@if (results !=null && results.Any())
{
    <p>There are @results.TotalItemCount items matching your search @searchModel.Term</p>
    foreach (var result in results)
    {
        <div class="row">
            <div class="col-lg-12">
                <a href="/@result.LiveUrlSegment"><h4 class="margin-top-10 margin-bottom-5">
                 @result.Name.StripHtml().TruncateString(200)
                                                  </h4></a>
                @{
                    if (result is TextPage)
                    {
                        <p>@result.BodyContent.StripHtml().TruncateString(200)</p>
                    }
                }
                <p class="font-small">Last updated @result.CreatedOn.ToShortDateString()</p>
            </div>
        </div>
        <hr class="margin-top-0 margin-bottom-0"/>
    }

    @Html.PageCurrentPage(results, i => new {page = i}, PagedListRenderOptions.PageNumbersOnly)
}
else
{
    <p>@Resource("No results returned from query").</p>
}