<%
  import org.exoplatform.web.application.Parameter ;
  
  def commentsList = uicomponent.getComments() ;
  def uicomment = uicomponent.getCommentComponent();
  if(commentsList.size() > 0) {
    java.text.SimpleDateFormat commentDateFormat = new java.text.SimpleDateFormat("h:mm a. EEE, MMM d, yyyy") ;
    def lastComment = commentsList.get(0) ;
    def rcontext = _ctx.getRequestContext() ;
    
%>
  <style>
		<% _ctx.include(uicomponent.getTemplateSkin("exo:comments", "Stylesheet")); %>
	</style>
  <div class="Comments ShowHideContainer">
		<div class="CommentBar" style="width: 600px;">
			<div class="LeftCommentBar">
			  <div class="RightCommentBar">
			    <div class="MiddleCommentBar">
			    	<div class="LabelPostedComment">
		  			  <%=_ctx.appRes("Comment.view.label.postedBy")%><span style="color:#f7941e">
		  			  <%if(lastComment.hasProperty("exo:commentor")){%>
		  			  	<%=lastComment.getProperty("exo:commentor").getString()%></span> 
		  			  <%}%>
		  			  <%=_ctx.appRes("Comment.view.label.at")%> 
		  			  <%if(lastComment.hasProperty("exo:commentDate")){%>
			  			  <%=commentDateFormat.format(lastComment.getProperty("exo:commentDate").getDate().getTime())%>
			  			<%}%>  
		  			</div>
		  			<div class="ShowComment">
			  			<div style="float: left;"><%=commentsList.size()%> <%=_ctx.appRes("Comment.view.label.comments")%></div>
			  			<div style="float: right;" onclick="eXo.ecm.ECMUtils.showHideComponent(this)"><a><%=_ctx.appRes("Comment.view.label.show-comments")%></a><span style="display: none"><a><%=_ctx.appRes("Comment.view.label.hide-comments")%></a></span></div>
			  			<div style="clear: both;"><span></span></div>
			  	  </div>
			 		</div>
				</div>
			</div>
		</div>
		<div class="ShowHideComponent" style="display: none;">
		  <%
		  def uiremovecomment = uicomponent.getRemoveComment();
		  for(comment in commentsList) {%>
		  	<div class="CommentInfo">
		  		<%=_ctx.appRes("Comment.view.label.comment-by")%> 
		  		<span style="color: orange; font-weight: bold;">
			  		<%if(comment.hasProperty("exo:commentor")){%>
			  			<%=comment.getProperty("exo:commentor").getString()%>
			  		<%}%>
		  		</span>
		  		<%
		  		  if(comment.hasProperty("exo:commentorEmail")) {
		  		    String email = comment.getProperty("exo:commentorEmail").getString() ;
		  		%>
    		  		- <%=_ctx.appRes("Comment.view.label.email")%>: <a href="mailto:$email">$email</a> -
    		  <%
    		    } 
			  		if(comment.hasProperty("exo:commentorSite")) {
			  		  String site = comment.getProperty("exo:commentorSite").getString() ;
		  		%>
		  			  (<%=_ctx.appRes("Comment.view.label.site")%>: <a href="$site" target="_blank">$site</a>) - <%=_ctx.appRes("Comment.view.label.at")%>
		  		<%}%>
		  		<%if(comment.hasProperty("exo:commentDate")){%>
		  			<%=commentDateFormat.format(comment.getProperty("exo:commentDate").getDate().getTime())%>
		  		<%}%>
		  		
		  		<%
		  		String commentor=null;
		  		String path = comment.getPath();
		  		String parentPath = comment.getSession().getWorkspace().getName().concat(":").concat(uicomponent.getNode().getPath());
		  		if(comment.hasProperty("exo:commentor")){
		  		  commentor=comment.getProperty("exo:commentor").getString();
			  	}
          if (commentor!=null && commentor.equals(rcontext.getRemoteUser())) {
	  		 %>
	  		 <% if (uicomment != null) {
	  		 %>
			  		<a href="<%=uicomment.event("Comment", org.exoplatform.ecm.webui.utils.Utils.formatNodeName(parentPath), new Parameter("nodePath", path))%>">
							<image class="EditComment" src="/eXoResources/skin/sharedImages/Blank.gif" alt="" title="<%=_ctx.appRes("Comments.tooltip.edit-comment")%>"/>
						</a>
				<%
	  		 Parameter[] params = [new Parameter("workspaceName", comment.getSession().getWorkspace().getName()), new Parameter("repository", uicomponent.getRepository())];
	  		%>
						<a href="<%=uiremovecomment.event("RemoveComment", org.exoplatform.ecm.webui.utils.Utils.formatNodeName(path), params)%>">
						<image class="RemoveAttachments" src="/eXoResources/skin/sharedImages/Blank.gif" alt="" title="<%=_ctx.appRes("Comments.tooltip.remove-comment")%>"/>
						</a>
				<%}}%>

		  	</div>
		  	<div class="CommentBox">  		
		  		<div class="CommentBoxTopLeft">
		  			<div class="CommentBoxTopRight">
		  				<div class="CommentBoxTopCenter"><span style="display:none"></span></div>
		  			</div>
		  		</div>
		  		<div class="CommentBoxMiddleLeft">
		  			<div class="CommentBoxMiddleRight">
		  				<div class="CommentBoxCenterBG">
		  					<%if(comment.hasProperty("exo:commentContent")){%>
		  						<%=comment.getProperty("exo:commentContent").getString()%>
		  					<%}%>
		  				</div>
		  			</div>
		  		</div>
		  		<div class="CommentBoxBottomLeft">
		  			<div class="CommentBoxBottomRight">
		  				<div class="CommentBoxBottomCenter"><span style="display:none"></span></div>
		  			</div>
		  		</div>
		  	</div>
			<%}%>
		</div>
  </div>
<%}%>