<%
	import org.exoplatform.webui.core.UIComponent;
  import org.exoplatform.webui.form.UIForm;
  import java.text.DateFormat;
  import java.text.SimpleDateFormat;
  import javax.jcr.Node;
  import javax.jcr.Session;
  import org.exoplatform.ecm.webui.utils.Utils;
  import org.exoplatform.services.ecm.publication.PublicationService;
  import org.exoplatform.services.wcm.publication.WCMPublicationService;
  import org.exoplatform.services.wcm.core.NodeLocation;

  String[] beanFields =  uicomponent.getBeanFields();  
  String[] beanActions =  uicomponent.getBeanActions();
  UIComponent uiParent = uicomponent.getParent() ;
  UIForm uiForm = uicomponent.getAncestorOfType(UIForm.class);
  DateFormat dateFormat = uicomponent.getDateFormat();
%>

<div id="$uicomponent.id">
  <table class="UIGrid" cellspacing="0">
    <thead>
      <tr class="UIWCMSearchContent">
        <%
	        int count = 0;
        		for(field in beanFields) {
       	%>
              		<th class="$field"><%=_ctx.appRes("UIContentSearchResult.header." + field)%></th>
        <%		}
        		if(beanActions != null) { 
        %>
        			<th class="action"><%=_ctx.appRes("UIContentSearchResult.header.action")%></th>
        <%		
        		}
        		
        %>
      </tr>
    </thead>
    <tbody>
    <%	
    	if(uicomponent.getUIPageIterator().getAvailable() < 1) {
    %>
      <tr>
        <td style="font-style:italic; color: #FF5604; text-align: center;" colspan="<%=beanFields.length+1%>">
          <%=_ctx.appRes("UIGrid.msg.empty")%>
        </td>
      </tr>  
    <%	} else { 
        def rowClass = null ;
        boolean even = true ;
        for (bean in uicomponent.getBeans())  {
          if(even) rowClass = "EvenRow" ;  
          else rowClass =  "OddRow" ; 
          even = !even ;
    %>
          <tr>
    <%
            String titleNode = bean.getTitle();
            String expect = uicomponent.getExpect(bean.getExcerpt());
            String path = bean.getPath();
            float score = bean.getScore();
            Node node = bean.getNode();
            def nodeExpression = NodeLocation.getExpressionByNode(node);
            String date = dateFormat.format(uicomponent.getCreateDate(node));
            WCMPublicationService wcmPublicationService = uicomponent.getApplicationComponent(WCMPublicationService.class);
            String publicationState = wcmPublicationService.getContentState(node);
            if (publicationState == null) publicationState = "";
    %>        
          <td>
            <div class="default16x16Icon ItemIcon <%=Utils.getNodeTypeIcon(node, "16x16Icon")%>" style="width: auto; height: auto; background-position: left top; padding-left: 20px">
              <div class="Text">$titleNode</div>
              <div class="Text">$expect</div>
              <div class="Text">$path</div>
              <div class="Text">$date</div>
            </div>
          </td>
          
          <td>
            <div class="Number">$score</div>
          </td>
          
          <td>
            <div class="Text">$publicationState</div>
          </td>
    <%
    	if(beanActions != null && beanActions.length > 0) { 
    %>
          <td class="action">
            <div class="ActionContainer">
              <img onclick="<%= uicomponent.event("Select", nodeExpression) %>" src="/eXoResources/skin/sharedImages/Blank.gif" class="SelectIcon" title="<%=_ctx.appRes("UIContentSearchResult.title.Select")%>" alt="<%=_ctx.appRes("UIContentSearchResult.title.Select")%>" />
              <img onclick="<%= uicomponent.event("View", nodeExpression) %>" src="/eXoResources/skin/sharedImages/Blank.gif" class="ViewIcon" title="<%=_ctx.appRes("UIContentSearchResult.title.View")%>" alt="<%=_ctx.appRes("UIContentSearchResult.title.View")%>" />                 
            </div>
          </td>
    <%
    	}
    %>
          </tr>
    <%
        }
      }
    %> 
    </tbody>
  </table> <!--End UIGrid-->
  <%
  if(uicomponent.getUIPageIterator().getAvailablePage() > 1) {
    _ctx.renderUIComponent(uicomponent.getUIPageIterator()) ;
  }
  %>
</div>
