
<%@page import="com.liferay.document.library.kernel.model.DLFileShortcut"%>
<%@page import="com.liferay.document.library.kernel.util.PDFProcessorUtil"%>
<%@page import="com.liferay.portal.kernel.dao.search.SearchContainer"%>
<%@ include file="init.jsp" %>

<%
	
	long folderId = assetPublisherDisplayContext.getRootFolder();
	int status = WorkflowConstants.STATUS_APPROVED;
	int max_delta = assetPublisherDisplayContext.getDelta();
	boolean position = assetPublisherDisplayContext.getPosition();
	String css = assetPublisherDisplayContext.getDisplayStyle();
	String styleID = assetPublisherDisplayContext.getStyleID();
	
	OrderByComparator orderByComparator = DLUtil.getRepositoryModelOrderByComparator("modifiedDate", "desc");
	List<FileEntry> fileEntries = DLAppServiceUtil.getGroupFileEntries(scopeGroupId, 0, folderId, currentMimeTypes, status, 0, max_delta, orderByComparator);
	
	List <Object> foldersAndFileEntriesAndFileShortcuts = DLAppServiceUtil.getFoldersAndFileEntriesAndFileShortcuts(scopeGroupId, folderId, WorkflowConstants.STATUS_ANY, 
		true, QueryUtil.ALL_POS, QueryUtil.ALL_POS);
	
	//List<DLFileEntry> dlssss = DLFileEntryLocalServiceUtil.getFileEntries(scopeGroupId, folder.getFolderId(), status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, orderByComparator);
	//System.out.println(fileEntries.size());
%>
<style>
<%= max_delta==1 ? "#"+styleID+" li.lfr-asset-item{width:100%;}" : "" %>
<%= assetPublisherDisplayContext.getCSS() %>

.pdf-column1{
	padding-left: 15px;
	padding-right: 15px;
	padding-bottom: 15px;
}

</style>

<%
	FileEntry fileEntryPDF = null;
	Folder subFolderPDF = null;
%>

<%
	if (assetPublisherDisplayContext.isallLevelsPDF()) {
		for (Object folderAndFileEntryAndFileShortcut: foldersAndFileEntriesAndFileShortcuts) {    
			if (folderAndFileEntryAndFileShortcut instanceof FileEntry) {
				fileEntryPDF = (FileEntry) folderAndFileEntryAndFileShortcut;
				
%>
	<div class="text-justify">
		<%= "file="+fileEntryPDF.getFileName() %><br>
	</div>
<%
			} else if (folderAndFileEntryAndFileShortcut instanceof Folder) {
				subFolderPDF = (Folder) folderAndFileEntryAndFileShortcut;
%>
	<div class="text-justify">
		<ul id="my-menu">
			<li><a href=""><%= subFolderPDF.getName() %></a>
					<ul style="display: none;">
						<%
							List<FileEntry> fileEntriessss = DLAppServiceUtil.getGroupFileEntries(scopeGroupId, 0, subFolderPDF.getFolderId(), currentMimeTypes, status, -1, -1, orderByComparator);
							for (FileEntry entry : fileEntriessss){
								FileVersion fileVersion = DLAppServiceUtil.getFileVersion(entry.getFileVersion().getFileVersionId());
						%>
						
						<li >
							<a href="<%= DLUtil.getDownloadURL(entry, fileVersion, themeDisplay, "") %>"><%= entry.getFileName() %>
						</li>
						
						<% } %>
					</ul>
			</li>
		</ul
		
	</div>


<%			}
		}
	}else{
%>

	<div class="text-justify">
		<ul class="display-style-icon list-unstyled row" id="<%= styleID %>">
		<%
			for(FileEntry fileEntry : fileEntries){
				
				FileVersion fileVersion = DLAppServiceUtil.getFileVersion(fileEntry.getFileVersion().getFileVersionId());
				String thumbnailImage = DLUtil.getPreviewURL(fileEntry, fileVersion, themeDisplay, "&videoThumbnail=1");
				if(VideoProcessorUtil.hasVideo(fileVersion)){
					
					String src = DLUtil.getPreviewURL(fileEntry, fileVersion, themeDisplay, "&videoPreview=1"+"&type=" + "mp4");
					//String oo = PropsUtil.get(PropsKeys.DL_FILE_ENTRY_PREVIEW_VIDEO_CONTAINERS);
		%>
					<li class="lfr-asset-item video" style="<%= fileEntries.size()==1 ? "text-align:center;" : "" %>">
						<video src="<%= src %>" poster="<%= thumbnailImage %>" controls width="<%= assetPublisherDisplayContext.getWidthVideo() %>"></video>
						<div class="cis-text-color" style="white-space: nowrap;"><%= fileEntry.getTitle() %></div>
					</li>
		<%
				}else if(ImageProcessorUtil.hasImages(fileVersion)){
		%>
					<li class="lfr-asset-item">
						<div class="image-link preview" href="<%= DLUtil.getPreviewURL(fileEntry, fileVersion, themeDisplay, "") %>">
							<div class="taglib-vertical-card entry-display-style">
								<div class="clients-item">
									<% if(!assetPublisherDisplayContext.isOneStaticPhoto()){ %>
									<div class="aspect-ratio aspect-ratio-bg-center aspect-ratio-bg-cover" style="background-image: url('<%= DLUtil.getPreviewURL(fileEntry,fileVersion, themeDisplay, "&imageThumbnail=1") %>');cursor: pointer;">
									</div>
									<% }else{ %>
									<img alt="" src="<%= DLUtil.getPreviewURL(fileEntry,fileVersion, themeDisplay, "&imageThumbnail=1") %>">
									<% } %>
								</div>
							</div>
							<div class="cis-text-color"><%= fileEntry.getTitle() %></div>
						</div>
					</li>
					
				
		
		<%
				}else if(PDFProcessorUtil.hasImages(fileVersion)){
					String imageURL = DLUtil.getPreviewURL(fileEntry, fileVersion, themeDisplay, "&previewFileIndex=1");
		%>
					
				
					<%-- <div class="image-link preview">
						<%= imageURL %>
					</div> --%>
					<%-- <li class="lfr-asset-item">
						<div class="image-link preview" href="<%= imageURL %>">
							<div class="taglib-vertical-card entry-display-style">
								<div class="clients-item">
									<% if(!assetPublisherDisplayContext.isOneStaticPhoto()){ %>
									<div class="aspect-ratio aspect-ratio-bg-center aspect-ratio-bg-cover" style="background-image: url('<%= imageURL %>');cursor: pointer;"></div>
									<% }else{ %>
									<img alt="" src="<%= imageURL %>">
									<% } %>
								</div>
								<div>
									<%= fileEntry.getTitle() %>
								</div>
							</div>
						</div>
					</li> --%>
					
	
					<div class="pdf-column1">
						<a href="<%= DLUtil.getDownloadURL(fileEntry, fileVersion, themeDisplay, "") %>">
							<img alt="" src="<%=request.getContextPath()%>/img/pdficon.png"> <span><%= fileEntry.getTitle() %></span>
						</a>
					</div>
					
	
		
		<%
				}
			}
		%>
		</ul>
	</div>
	
<%
	}
%>

<%-- <div class="text-justify">
	<%
		DLFolder folder = DLFolderLocalServiceUtil.fetchFolder(scopeGroupId, DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, "video");
		if (Validator.isNotNull(folder)){
			List<DLFileEntry> dls = DLFileEntryLocalServiceUtil.getFileEntries(scopeGroupId, folder.getFolderId(), status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, orderByComparator);
			for(DLFileEntry dl : dls){

			}
		}
	%>
<div> --%>

<aui:script>
$(document).ready(function() {
  $('ul#my-menu ul').each(function(index) {
    $(this).prev().addClass('collapsible').click(function() {
      if ($(this).next().css('display') == 'none') {
        $(this).next().slideDown(200, function () {
          $(this).prev().removeClass('collapsed').addClass('expanded');
        });
      }else {
        $(this).next().slideUp(200, function () {
          $(this).prev().removeClass('collapsed').addClass('expanded');
          $(this).find('ul').each(function() {
            $(this).hide().prev().removeClass('expanded').addClass('collapsed');
          });
        });
      }
      return false;
    });
  });
});
</aui:script>

<aui:script use="aui-carousel,aui-image-viewer">

		
		var imageViewer = new A.ImageViewer(
			  {
				caption: '',
				captionFromTitle: true,
				centered: true,
				imageAnim: {
				 duration: 1,
				 easing: 'easeIn'
				},
				intervalTime: 7,
				links: '#<%= styleID %> .image-link.preview',
				playing: true,
				preloadAllImages: true,
				preloadNeighborImages: true,
				showInfo: false,
				showPlayer: true,
				zIndex: 1
			  }
		).render();
	
</aui:script>





