<%
  import java.util.Locale;
  import java.text.DateFormat;
  import org.exoplatform.wiki.webui.UIWikiPortlet;  
  import org.exoplatform.wiki.commons.Utils;
  import org.apache.commons.lang.StringEscapeUtils;
  
  def currentVersions = uicomponent.getVersionList(currentWikiPage);
  def rcontext = _ctx.getRequestContext() ;
  DateFormat df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT, rcontext.getLocale());
  def showHistoryId = UIWikiPortlet.WIKI_PORTLET_ACTION_PREFIX + "ShowHistory";
%>

<div class="uiPageInfoItem uiPageInfoChanges">
  <table class=" uiGrid table table-hover table-striped" width="100%" cellspacing="0" cellpadding="0">
    <caption><h6 class="pageInfoTitle"><%= _ctx.appRes("UIWikiPageInfo.label.recent-changes")%></h6></caption>
    <thead>
      <tr>
        <th ><%= _ctx.appRes("UIWikiPageInfo.label.time")%></th>
	    <th ><%= _ctx.appRes("UIWikiPageInfo.label.editor")%></th>
	  </tr>
	</thead>
	<tbody>
	  <%
	    def isCurrentVersion = true;
	    currentVersions?.each {version ->

	      def versionLabel = version.getName();
	      def versionNumber= versionLabel;
	      if(isCurrentVersion){
	    	isCurrentVersion = false;
	        versionLabel = _ctx.appRes("UIWikiPageVersionsList.label.Current") + " (" + _ctx.appRes("UIWikiPageInfoArea.label.version-short").toLowerCase() +"." + versionLabel + ")";
	      } else {
	        versionLabel = _ctx.appRes("UIWikiPageInfoArea.label.version-short").toLowerCase() +"." + versionLabel;
	      }
	      def viewLinkId = UIWikiPortlet.WIKI_PORTLET_ACTION_PREFIX + "ViewRevision_"+versionNumber;
	      def viewLink = uicomponent.event("ViewRevision", version.getName());
	      def updatedDate = df.format(version.getUpdatedDate());
	      def author = StringEscapeUtils.escapeHtml(Utils.getFullName(version.getAuthor()));
	    %>
	      <tr>
	        <td>
	          <a href="#ViewRevision_<%=versionNumber%>" >$versionLabel</a>
	          <a style="display: none;" id="$viewLinkId" onclick="<%=uicomponent.event("ViewRevision", versionNumber)%>">&nbsp;</a>
	        </td>
	        <td  class="Editor">$author</td>
	      </tr>
	    <% } %>
	    
	   <tr>
	     <td colspan="2" style="padding: 0px;">
           <% if (currentVersions.size() > 0) { %>
		     <div class="actionCenter">
			   <button type="button" class="btn" onclick="<%=uicomponent.event("ShowHistory")%>"><%= _ctx.appRes("UIWikiPageInfo.label.view-page-history")%></button>
			 </div>
		   <% } %>
		 </td>
	   </tr>
	 </tbody>
  </table>
</div>