<%
  import org.exoplatform.web.application.Parameter;
  import org.exoplatform.wiki.webui.UIWikiPortlet;
%>
<div class="uiWikiPageVersionsCompare" id="$uicomponent.id">
<%
  String showHistory = uicomponent.SHOW_HISTORY;
  String anchor = "#" + showHistory;
  String showHistoryLinkId = UIWikiPortlet.WIKI_PORTLET_ACTION_PREFIX + showHistory;;
  String showHistoryLink = uicomponent.event(uicomponent.SHOW_HISTORY);
  String fromVersionName = uicomponent.getFromVersionName();
  String fromVersionViewLink = uicomponent.event(uicomponent.VIEW_REVISION, fromVersionName);
  String fromVersionAuthor = uicomponent.getFromVersionAuthor();
  String fromUpdatedDate = uicomponent.getFromVersionUpdateDate();
  String previousCompare = "";
  String previousCompareLink = "";
  Parameter[] parameters = new Parameter[2];
  if(!"1".equals(fromVersionName)){
    String previous = String.valueOf(Integer.valueOf(fromVersionName) - 1);
    previousCompare = "<< " + _ctx.appRes("UIWikiPageVersionsCompare.label.PreviousAndNextCompare").replace("{0}", "<b>" + previous + "</b>").replace("{1}", "<b>" + fromVersionName + "</b>");
    parameters[0] = new Parameter(uicomponent.FROM_PARAM, previous);
    parameters[1] = new Parameter(uicomponent.TO_PARAM, fromVersionName);
    previousCompareLink = uicomponent.event(uicomponent.COMPARE_ACTION, null, parameters);
  }
  
  String toVersionName = uicomponent.getToVersionName();
  String toVersionViewLink = uicomponent.event(uicomponent.VIEW_REVISION, toVersionName);
  String toVersionAuthor = uicomponent.getToVersionAuthor();
  String toUpdatedDate = uicomponent.getToVersionUpdateDate();
  String nextCompare = "";
  String nextCompareLink = "";
  if(!toVersionName.equals(uicomponent.getCurrentVersionIndex())){
    String next = String.valueOf(Integer.valueOf(toVersionName) + 1);
    nextCompare = _ctx.appRes("UIWikiPageVersionsCompare.label.PreviousAndNextCompare").replace("{0}", "<b>" + toVersionName + "</b>").replace("{1}","<b>" + next + "</b>") + " >>";
    parameters[0] = new Parameter(uicomponent.FROM_PARAM, toVersionName);
    parameters[1] = new Parameter(uicomponent.TO_PARAM, next);
    nextCompareLink = uicomponent.event(uicomponent.COMPARE_ACTION, null, parameters);
  } else {
    toVersionName = "Current";
  }

  String titleCompare = _ctx.appRes("UIWikiPortlet.label.Compare-Version");
  String fromChangeVersionInfoLabel = _ctx.appRes("UIWikiPageVersionsCompare.label.ChangeVersionInfo");
  fromChangeVersionInfoLabel = fromChangeVersionInfoLabel.replace("{0}", fromVersionName +  "</b>");
  fromChangeVersionInfoLabel = fromChangeVersionInfoLabel.replace("{1}", "<b class=\"admin\">" + fromVersionAuthor + "</b>");
  String toChangeVersionInfoLabel = _ctx.appRes("UIWikiPageVersionsCompare.label.ChangeVersionInfo");
  if(toVersionName.equals("Current")){
  	String currentVersion= _ctx.appRes("UIWikiPageVersionsCompare.label.CurrentVersion");
  	toChangeVersionInfoLabel = currentVersion.replace("{0}", "" +  "</b>");
  	toChangeVersionInfoLabel = toChangeVersionInfoLabel.replace("{1}", "<b class=\"admin\">" + toVersionAuthor + "</b>");
  }
  else{
  	toChangeVersionInfoLabel = toChangeVersionInfoLabel.replace("{0}", toVersionName +  "</b>");
  	toChangeVersionInfoLabel = toChangeVersionInfoLabel.replace("{1}", "<b class=\"admin\">" + toVersionAuthor + "</b>");
  }
  String wordAddedRemovedLabel = _ctx.appRes("UIWikiPageVersionsCompare.label.this-word-was-added-removed");
  wordAddedRemovedLabel = wordAddedRemovedLabel.replace("{0}", "</span><span class=\"lineRemoved\">");
  wordAddedRemovedLabel = wordAddedRemovedLabel.replace("{1}", "</span><span>");
  wordAddedRemovedLabel = wordAddedRemovedLabel.replace("{2}", "</span><span class=\"lineAdded\">");
  wordAddedRemovedLabel = wordAddedRemovedLabel.replace("{3}", "</span>");
%>
	<div class="comparedForm ">
		<h4><%= titleCompare %></h4>
		<div class="clearfix">
			<pre class="changeVersionForm pull-left">
				<b class="changeVersionInfo"><%= fromChangeVersionInfoLabel %>
				<span class="dateChange"><%= _ctx.appRes("UIWikiPageVersionsCompare.label.DateChange").replace("{0}", fromUpdatedDate); %>.</span>
				<a class="changes" href="$previousCompareLink"><%= previousCompare %></a>
			</pre>
			<div class="comparedWith pull-left"> <%= _ctx.appRes("UIWikiPageVersionsCompare.label.ComparedWith"); %> </div>
			<pre class="changeVersionForm pull-left">
				<b class="changeVersionInfo"><%= toChangeVersionInfoLabel %>
				<span class="dateChange"><%= _ctx.appRes("UIWikiPageVersionsCompare.label.DateChange").replace("{0}", toUpdatedDate); %>.</span>
				<a class="changes" href="$nextCompareLink"><%= nextCompare %></a>
			</pre>
		</div>
		<div class="clearfix">
			<pre class="changeVersionForm pull-right">
				<b class="changeVersionInfo"><%= _ctx.appRes("UIWikiPageVersionsCompare.label.Key"); %></b><br />
				<span class="lineRemoved"><%= _ctx.appRes("UIWikiPageVersionsCompare.label.this-line-was-removed"); %></span><br />
				<span><%= wordAddedRemovedLabel %><br />
				<span class="lineAdded"><%= _ctx.appRes("UIWikiPageVersionsCompare.label.this-line-was-added"); %></span>
			</pre>
		</div>
	</div>
	<div class="changedForm">
		<h6><%= _ctx.appRes("UIWikiPageVersionsCompare.label.Changes").replace("{0}",  String.valueOf(uicomponent.changes)); %></h6>
		<button type="button" class="btn" onclick="javascript:eXo.wiki.UIWikiAjaxRequest.makeNewHash('#$showHistory');"> <%= _ctx.appRes("UIWikiPageVersionsCompare.label.ViewPageHistory"); %></button><br />
		<a style="display:none" id="$showHistoryLinkId" onclick="$showHistoryLink"></a>
		<%= uicomponent.differencesAsHTML %>
	</div>
</div>
