<%
	var containerId = m.lib.containerId, tuix = m.tuix, lib = m.lib;
	zenario.sendSignal("eventListPreDisplay", {containerId: containerId, microTemplate: "fea_list_blocks", tuix: tuix, lib: lib});
%>


{{m.lib.displayDevTools()}}


<div class="{{m.lib.wrapperClassName()|e}} zfea_blocks">
	{{m.tuix.header_html}}
	
	<% if (m.tuix.title !== undefined) { %>
	    <% if (m.tuix.title_tags) { %>
		    <{{m.tuix.title_tags|e}}>{{m.tuix.title|e}}</{{m.tuix.title_tags|e}}>
		<% } else { %>
		    <h1>{{m.tuix.title|e}}</h1>
		<% } %>
	<% } %>
	
	<div class="zfea_back_button">
		<% if (zenarioT.find(m.thus.sortedCollectionButtons, "back")) { %>
			{{m.lib.pMicroTemplate("button", m.thus.sortedCollectionButtons, "back")}}
		<% } %>
	</div>
	<div class="zfea_buttons zfea_top_buttons">
		<% if (zenarioT.find(m.thus.sortedCollectionButtons, "top")) { %>
			{{m.lib.pMicroTemplate("button", m.thus.sortedCollectionButtons, "top")}}
		<% } %>
	</div>
	
	<% var ci, col, chi, child, bi, button, oi, log, logName, gi, lg, lgName, ii, item, tag, showParent, headerId = false, firstItem = true; %>
	
	{{m.lib.pMicroTemplate("list_search_and_sort", m)}}
	
	<% if (m.tuix.item_count_message && m.tuix.__item_count__ > 1) { %>
		<div class="item_count">
			<p>{{m.tuix.item_count_message.replace("[[count]]", m.tuix.__item_count__)|e}}</p> 
		</div>
	<% } %>
	
	<% if (m.tuix.subtitle !== undefined) { %>
		<div class="subtitle">
			<h1>{{m.tuix.subtitle|e}}</h1>
		</div>
	<% } %>
	
	<% if (m.thus.sortedCollectionButtons.length) { %>
		<div class="sorted_buttons">
			<% if (zenarioT.find(m.thus.sortedCollectionButtons, ["above_list", "column_header", undefined]) && !_.isEmpty(m.tuix.columns)) { %>
				{{m.lib.pMicroTemplate("button", m.thus.sortedCollectionButtons, ["above_list", "column_header", undefined])}}
			<% } %>
		</div>
	<% } %>
	
	<% if (!_.isEmpty(m.tuix.columns)) { %>
	
		<% foreach (m.thus.sortedListOuterGroupings as oi => logName) { %>
			<% log = m.tuix.list_outer_groupings && m.tuix.list_outer_groupings[logName]; %>
			
			<% if (log) { %>
				{{m.lib.pMicroTemplate("list_block_outer_grouping", log)}}
			<% } %>
	
			<% foreach (m.thus.sortedListGroupings as gi => lgName) { %>
				<% lg = m.tuix.list_groupings && m.tuix.list_groupings[lgName]; %>
				
				<% if (lg) { %>
					
					<% if (log && logName != lg.list_outer_grouping) { %>
						<% continue; %>
					<% } %>
					
					{{m.lib.pMicroTemplate("list_block_grouping", lg)}}
				<% } %>
		
				<div class="zfea_block_list_wrap">
					<% foreach (m.thus.sortedItems as ii => item) { %>
		
						<% if (lg && lgName != item.list_grouping) { %>
							<% continue; %>
						<% } %>
				
						<% if (m.tuix.has_headers) { %>
							<% if (item.header_id != headerId) { %>
								<% if (headerId !== false) { %> 
									</div></div>
								<% } %>
								<% headerId = item.header_id; %>
								<div class="section">
									<h4>{{item.header_name|e}}</h4>
									<div class="zfea_block_list_wrap_inner">
							<% } %>
						<% } %>
				
						<div class="zfea_block item_{{item.id|e}} {{item.row_class|e}}">
							
							<% if (item.__sortedItemButtons.length && zenarioT.find(item.__sortedItemButtons, "top")) { %>
								<div class="buttons block_buttons_top">
									{{m.lib.pMicroTemplate("button", item.__sortedItemButtons, "top")}}
								</div>
							<% } %>
							
							<% var sameRow = false; %>
							<% foreach (m.thus.sortedColumns as ci => col) { %>
						
								<% if (!(showParent = m.lib.columnVisibleForItem(col.id, item.id))) { %>
									<% var blockInvis = true; %>
									
									<% if (col.children) { %>
										<% foreach (col.children as chi => child) { %>
											<% if (m.lib.columnVisibleForItem(child.id, item.id)) { %>
												<% blockInvis = false; %>
											<% } %>
										<% } %>
									<% } %>
									
									<% if (blockInvis) { %>
										<% continue; %>
									<% } %>
								<% } %>
						
								<% if (m.thus.sortedColumns[+ci + 1] && m.thus.sortedColumns[+ci + 1].same_row && !sameRow) { %>
									<% sameRow = true; %>
									<div class="wrap_div">
								<% } %>
						
								<% tag = col.tag ? col.tag : "p"; %>
								<div
									id="{{('zfea_' + m.lib.containerId + '_row_' + ii + '_col_' + ci)|e}}"
									data-label="{{col.title|e}}" 
									class="
										block_view_box
										column_{{col.id|e}} 
										{{col.css_class|e}}
										<% if (ci == 0) { %>
											zfea_first_col
										<% } %>
										<% if (item.cell_css_classes && item.cell_css_classes[col.id]) { %>
											{{item.cell_css_classes[col.id]|e}}
										<% } %>
									"
								>
									<div class="icon"></div>
									
									<div class="
										label
										<% if (col._is_block) { %>
											<% if (col._is_metric) { %>
												metric
											<% } else { %>
												real_time
											<% } %>
										<% } %>
									">
									    <% if (col.show_title_in_block_view && col.title) { %>
   											<div class="field_label resize_text">{{col.title|e}}</div>
										<% } %>
										
										<% if (zenario.defined(col.previous_label) && zenario.defined(item["prev__" + col.id])) { %>
											<div class="block_boxes period_boxes">
												<div class="box_wrapper this_wrapper">
													<div class="box_label">
														{{col.current_label|e}}
													</div>
													<div class="resize_text">
														{{item[col.id]|e}}
													</div>
												</div>
												<div class="box_wrapper previous_wrapper">
													<div class="box_label">
														{{col.previous_label|e}}
													</div>
													<div class="resize_text">
														{{item["prev__" + col.id]|e}}
													</div>
												</div>
											</div>
											

										<% } else if (col.children) { %>
											<div class="block_boxes parent_child_boxes">
												<% if (showParent && zenario.defined(item[col.id])) { %>
													<div class="box_wrapper parent_wrapper">
														<div class="resize_text">
															{{m.lib.pMicroTemplate("list_cell", {col: col, item: item})}}
														</div>
													</div>
												<% } %>
												
												<% foreach (col.children as chi => child) { %>
													<% if (m.lib.columnVisibleForItem(child.id, item.id)) { %>
														<div class="box_wrapper child_wrapper child_wrapper_{{child.id|e}} {{child.css_class|e}}">
															<div class="resize_text">
																{{m.lib.pMicroTemplate('list_cell', {col: child, item: item})}}
															</div>
														</div>
													<% } %>
												<% } %>
											</div>
											
										<% } else { %>
											<div class="field_value resize_text">
												{{m.lib.pMicroTemplate("list_cell", {col: col, item: item})}}
											</div>
										<% } %>
										
										<% if (col.cell_tooltip) { %>
										    <i class="info_icon" title="{{col.cell_tooltip|e}}"></i>
										<% } %>
									</div>
								</div>
						
								<% if (col.same_row && sameRow && (!m.thus.sortedColumns[+ci + 1] || !m.thus.sortedColumns[+ci + 1].same_row)) { %>
									<% sameRow = false; %>
									</div>
								<% } %>
							<% } %>
							
							<% if (item.__sortedItemButtons.length && zenarioT.find(item.__sortedItemButtons, ["bottom", undefined])) { %>
								<div class="buttons block_buttons_bottom">
									{{m.lib.pMicroTemplate("button", item.__sortedItemButtons, ["bottom", undefined])}}
								</div>
							<% } %>
						</div>
				
					<% } %>
			
					<%
						if (!zenarioL.mobile && m.lib.mode != "view_data_pool_block") {
							m.lib.after(function() {
								var maxHeight = 0;
								$("#" + m.lib.containerId + " .zfea_block_list_wrap .zfea_block")
									.each(function() { maxHeight = Math.max(maxHeight, $(this).height()); })
									.height(maxHeight);
							});
						}
					%>
					<% if (m.thus.sortedItems.length == 0) { %>
						<% if (m.tuix.no_items_message) { %>
							<div class="zfea_no_items_message">{{m.tuix.no_items_message}}</div>
						<% } %>
					<% } %>
				</div>
						
				<% if (lg) { %>
					{{m.lib.pMicroTemplate("list_block_grouping_end", lg)}}
				<% } %>
			<% } %>
			
			<% if (log) { %>
				{{m.lib.pMicroTemplate("list_block_outer_grouping_end", log)}}
			<% } %>
		<% } %>
	<% } %>
	
	{{m.lib.pMicroTemplate("list_pagination", m)}}
	
	{{m.tuix.footer_html}}
</div>


<%
	m.lib.after(function() {
		zenario.sendSignal("eventListPostDisplay", {containerId: containerId, microTemplate: "fea_list_blocks", tuix: tuix, lib: lib});
	});
%>
