<%
  import org.exoplatform.container.ExoContainerContext;
  import org.exoplatform.wiki.service.WikiService;
  import org.exoplatform.services.jcr.util.IdGenerator;
  import org.exoplatform.wiki.webui.control.action.AddRelatedPageActionComponent;
  import org.exoplatform.wiki.webui.control.action.RemoveRelatedPageActionComponent;
%>
<div class="uiPageInfoItem uiPageInfoRelatedPage">
  <%
    WikiService wikiService = ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(WikiService.class);
    def currentWikiPage = uicomponent.getCurrentPage();
    def relatedPages = wikiService.getRelatedPagesOfPage(currentWikiPage);
  %>
  <table class="uiGrid table table-hover table-striped" >
    <caption><h6 class="pageInfoTitle"><%= _ctx.appRes("UIWikiPageInfo.label.related-pages") %></h6></caption>
	<thead>
      <tr>
	    <th><%= _ctx.appRes("UIWikiPageInfo.label.wiki")%></th>
	    <th><%= _ctx.appRes("UIWikiPageInfo.label.related-pages")%></th>
	    <% if (uicomponent.isHasExtension()) { %>
          <th class="center"><%= _ctx.appRes("UIWikiPageInfo.label.actions")%></th>
        <% } %>
	  </tr>
	</thead>
	<tbody>
	  <%
	    def breadcrumbComponent = uicomponent.breadcrumb;
	    relatedPages.each {rp ->
	      def wikiParams = org.exoplatform.wiki.utils.Utils.getWikiPageParams(rp);
	      def breadcrumbDatas = uicomponent.getBreadcrumbDatas(rp);
	       
	      breadcrumbComponent.setBreadCumbs(breadcrumbDatas);
	      breadcrumbComponent.setId(breadcrumbComponent.getId()+ IdGenerator.generate());
          def rmAction = null; 
	      if (uicomponent.isHasExtension()) {
            def rmComponent = uicomponent.getChild(RemoveRelatedPageActionComponent.class);
	        rmAction = rmComponent.getRemovePageActionLink(wikiParams);
          }
	  %>
	  <tr>
	    <td><%=uicomponent.getGroupName(wikiParams.getType(), wikiParams.getOwner()); %></td>
	    <td><% uicomponent.renderChild(breadcrumbComponent); %></td>
	    <% if(uicomponent.isHasExtension()) {%>
	      <td class="center">
	        <a href="javascript:void(0);" onclick="$rmAction" class="actionIcon" rel="tooltip" data-placement="bottom" title="<%= _ctx.appRes("MoreExtensionContainer.action.DeletePage"); %>"><i class="uiIconDelete uiIconLightGray"></i></a></div>
	      </td>
	    <% }%>
	  </tr>
	 <% } %>
	   
	 <% if (relatedPages.size() == 0) { %>
	   <tr>
	    <td class="empty center" colspan="3"><%=_ctx.appRes("UIGrid.msg.empty")%></td>
	   </tr>
	 <% } %>
	   <tr>
	     <td colspan="3" style="padding: 0px;">
           <% if(uicomponent.isHasExtension()) {
                uicomponent.renderChild(AddRelatedPageActionComponent.class);
		      } 
		   %>
		 </td>
	   </tr>
	 </tbody>
  </table>
</div>
