<%
  import org.exoplatform.services.wcm.search.SiteSearchService;
  def pageMode = uicomponent.getPageMode();

  if (SiteSearchService.PAGE_MODE_MORE.equals(pageMode)) {
  	def currentPage = uicomponent.getCurrentPage();
%>

<div class="showMore" style="display:block">

  <button type="button" class="btn" value="<%=_ctx.appRes("UIPaginatorDefault.label.more")%>" onclick="<%=uicomponent.event("ShowPage","${currentPage + 1}")%>"><%=_ctx.appRes("UIPaginatorDefault.label.more")%></button>

</div>

<%
  } else if (SiteSearchService.PAGE_MODE_PAGINATION.equals(pageMode)) {
    def currentPage = uicomponent.getCurrentPage();
    def totalPage = uicomponent.getAvailablePage();
    String previousPage = _ctx.appRes("UIPaginatorDefault.label.previous");
    String nextPage = _ctx.appRes("UIPaginatorDefault.label.next");
%>

<div class="pagination uiPageIterator clearfix">
	<ul class="pull-right">
		
  <% if( currentPage - 1 > 0 ){%>
	  	<li>
	      <a href="<%=uicomponent.event("ShowPage","${currentPage - 1}")%>" data-placement="bottom" rel="tooltip" data-original-title="Previous Page"><i class="uiIconPrevArrow"></i></a>
	  	</li>
  <% } else { %>
		<li class="disabled">
			<a data-placement="bottom" rel="tooltip" data-original-title="Previous Page"><i class="uiIconPrevArrow"></i></a>
		</li>
	<%  } %>
  <%
  int min = 1;
  int max = totalPage;
  if(totalPage > 5 && currentPage > 2){
    min = currentPage - 2;
    max = currentPage + 3;
    if (max > totalPage) max = totalPage;
  } else if( totalPage > 5 && currentPage < 3 ){
    min = 1;
    max = 6;
  }
  for( i in min..max) { %>
	
  <%  if( i == currentPage) { %>
  	<li class="active">
	    <a ><%=i%></a>
	</li>
  <%  } else { %>
  	<li>
	    <a href="<%=uicomponent.event("ShowPage","$i")%>"><%=i%></a>
	 </li>
  <%  } %>
  <%}%>
		
		
  <% if(currentPage + 1 <= totalPage) { %>
	  	<li>
	       <a href="<%=uicomponent.event("ShowPage","${currentPage + 1}")%>" data-placement="bottom" rel="tooltip" data-original-title="Next Page"><i class="uiIconNextArrow"></i></a>
	  	</li>
  <% } else {%>
	  	<li class="disabled">
	       <a data-placement="bottom" rel="tooltip" data-original-title="Next Page"><i class="uiIconNextArrow"></i></a>
	  	</li>
  <%  } %>	
	</ul>
	<p class="pull-right">
		<span>Total pages:</span>
		<span class="pagesTotalNumber">$totalPage</span>
	</p>
</div>

<%
  }
%>
