@using OurUmbraco.Our.Examine
@inherits Umbraco.Web.Macros.PartialViewMacroPage

@{
    var orderMode = !string.IsNullOrEmpty(Request["orderBy"]) ? Request["orderBy"] : "updateDate";
    var page = !string.IsNullOrEmpty(Request["page"]) ? int.Parse(Request["page"]) : 1;
    var category = Request["category"];
    var version = Request["version"];
    var term = Request["term"];
    var pageSize = 50;

    OurSearcher searcher = new OurSearcher(term, orderBy: orderMode);
    
    IEnumerable<SearchResult> result = new List<SearchResult>();
    var url = "orderBy=" + orderMode + "&q=" + term + "&version=" + version;
    var pages = 0;
    
    if(string.IsNullOrEmpty(term) == false){
        var search = searcher.Search();
        var total = search.SearchResults.TotalItemCount;
        pages = (total / pageSize) + 1;
        result = search.SearchResults.Skip((page-1) * pageSize).Take(pageSize);
    }
}

<!-- FORUM OVERVIEW START -->
	<section class="search-results">
		<div>
			<!-- FORUM HEADER START -->
			<div class="utilities">
				<ul id="breadcrumb">
					<li><a href="/" rel="nofollow">Our Umbraco</a></li>
					<li><a href="#" rel="nofollow">Search</a></li>
					<li><a href="#" rel="nofollow">@term</a></li>
				</ul>
			</div>

            <form action="/search" >
                <div class="search-big">
                    <input type="search" name="term" required value="@term">
                    <label for="search">Search</label>
                </div>
            </form>

			<section>

				<div class="search-all-results equalizer">

                    @if(string.IsNullOrEmpty(term) == false){
					    <ul>
                            @foreach(var item in result){
                            <li>
                                @{
                                    var icon = "icon-Chat";
                                    if(item.Fields["nodeTypeAlias"] == "project"){
                                        icon = "icon-Box";
                                    }else if(item.Fields["nodeTypeAlias"] == "documentation"){
                                        icon = "icon-Book-alt";   
                                    }
                                }
							    <a href="#">
								    <div class="type-icon">
									    <i class="@icon"></i>
								    </div>

								    <div class="type-context">
									    <div class="type-name">@item.Fields["nodeName"]</div>
									    <div class="type-description">@item.Fields["body"].Truncate(300)</div>
								    </div>
							    </a>
						    </li>
                            }
					    </ul>
                        
                        <nav class="pagination" role="navigation">
                            @if(page > 1){
	                            <a class="prev" href="?page=@(page-1)&@url">Prev</a>
                            }

                            @for (int i = 1; i <= pages; i++)
                            {
                                    <a class="@Umbraco.If(i == page, "active")" href="?page=@i&@url">@i</a>
                            }
		
                            @if(page < pages){
                                <a class="next" href="?page=@(page+1)&@url">Next</a>
                            }
                        </nav>
                    }
				</div>

                

			</section> <!-- Search end -->

		</div>
	</section>
	<!-- FORUM OVERVIEW END -->