<xf:title>{{ phrase('nodes') }}</xf:title>

<xf:pageaction>
	<div class="buttonGroup">
		<xf:button href="{{ link('nodes/add') }}" icon="add" overlay="true">{{ phrase('add_node') }}</xf:button>
		<xf:button href="{{ link('nodes/sort') }}" icon="sort" overlay="true" />
	</div>
</xf:pageaction>

<xf:if is="$nodeTree.countChildren()">
	<div class="block">
		<div class="block-outer">
			<xf:macro template="filter_macros" name="quick_filter" arg-key="nodes" arg-class="block-outer-opposite" />
		</div>
		<div class="block-container">
			<div class="block-body">
				<xf:datalist>
					<xf:foreach loop="$nodeTree.getFlattened(0)" value="$treeEntry">
						<xf:set var="$node" value="{$treeEntry.record}" />
						<xf:datarow>
							<xf:cell class="dataList-cell--min">
								<xf:macro name="node_icon" arg-node="{$node}" />
							</xf:cell>
							<xf:cell class="dataList-cell--link dataList-cell--main" hash="{$node.node_id}">
								<a href="{{ link('nodes/edit', $node) }}">
									<div class="u-depth{$treeEntry.depth}">
										<div class="dataList-mainRow">
											{$node.title}
											<span class="dataList-hint" dir="auto">
												{$node.NodeType.title}
												<xf:if is="
													$node.node_type_id == 'Forum'
													AND $node.Data.TypeHandler
													AND $node.Data.forum_type_id != 'discussion'
												">
													({{ $node.Data.TypeHandler.getTypeTitle() }})
												</xf:if>
											</span>
										</div>
									</div>
								</a>
							</xf:cell>
							<xf:action
								class="{{ {$customPermissions.{$node.node_id}} ? 'dataList-cell--highlighted' : '' }}"
								href="{{ link('nodes/permissions', $node) }}">
								{{ phrase('permissions') }}
							</xf:action>
							<xf:if is="{$moderators.{$node.node_id}}">
								<xf:popup class="dataList-cell--action u-hideMedium"
									label="{{ phrase('moderators_count_x', {'moderators': count({$moderators.{$node.node_id}})}) }}">

									<div class="menu" data-menu="menu" aria-hidden="true">
										<div class="menu-content">
											<h3 class="menu-header">{{ phrase('moderators') }}</h3>
											<xf:foreach loop="{$moderators.{$node.node_id}}" value="$moderator">
												<a href="{{ link('moderators/content/edit', $moderator) }}" class="menu-linkRow">{$moderator.User.username}</a>
											</xf:foreach>
											<hr class="menu-separator" />
											<a href="{{ link('moderators/add', null, {'type': 'node', 'type_id': {'node': $node.node_id}}) }}" class="menu-linkRow">{{ phrase('add_moderator') }}</a>
										</div>
									</div>
								</xf:popup>
							<xf:else />
								<xf:action href="{{ link('moderators/add', null, {'type': 'node', 'type_id': {'node': $node.node_id}}) }}" class="u-hideMedium">{{ phrase('add_moderator') }}</xf:action>
							</xf:if>
							<xf:popup class="dataList-cell--action u-hideMedium"
								label="{{ phrase('add...') }}">

								<div class="menu" data-menu="menu" aria-hidden="true">
									<div class="menu-content">
										<h3 class="menu-header">{{ phrase('add...') }}</h3>
										<a href="{{ link('nodes/add', null, {'parent_node_id': $node.parent_node_id}) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('sibling') }}</a>
										<a href="{{ link('nodes/add', null, {'parent_node_id': $node.node_id}) }}" class="menu-linkRow" data-xf-click="overlay">{{ phrase('child') }}</a>
									</div>
								</div>
							</xf:popup>
							<xf:delete href="{{ link('nodes/delete', $node) }}" />
						</xf:datarow>
					</xf:foreach>
				</xf:datalist>
			</div>
			<div class="block-footer">
				<span class="block-footer-counter">{{ display_totals($nodeTree.getFlattened(0)) }}</span>
			</div>
		</div>
	</div>
<xf:else />
	<div class="blockMessage">{{ phrase('no_items_have_been_created_yet') }}</div>
</xf:if>

<xf:macro name="node_icon" arg-node="!">
	<xf:if is="$node.node_type_id == 'Forum' AND $node.Data.TypeHandler">
		<xf:set var="$typeIcon" value="{{ $node.Data.TypeHandler.getTypeIconClass() }}" />
		<xf:if is="$typeIcon">
			<xf:fa icon="{$typeIcon}" />
		<xf:else />
			<i class="nodeIcon nodeIcon--{$node.node_type_id}"></i>
		</xf:if>
	<xf:else />
		<i class="nodeIcon nodeIcon--{$node.node_type_id}"></i>
	</xf:if>
</xf:macro>