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

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

<xf:form action="{{ link('navigation/toggle') }}" class="block" ajax="true">
	<div class="block-outer">
		<xf:macro template="filter_macros" name="quick_filter" arg-key="navigation" arg-class="block-outer-opposite" />
	</div>
	<div class="block-container">
		<div class="block-body">
			<xf:datalist>
				<xf:macro name="navigation_list" arg-children="{$tree}" />
			</xf:datalist>
		</div>
		<div class="block-footer">
			<span class="block-footer-counter">{{ display_totals($tree.getFlattened(0)) }}</span>
		</div>
	</div>
</xf:form>

<xf:macro name="navigation_list" arg-children="!" arg-depth="1">
	<xf:foreach loop="$children" value="$child">
		<xf:macro name="navigation_list_entry" arg-navigation="{$child.record}" arg-children="{$child.children}" arg-depth="{$depth}" />
	</xf:foreach>
</xf:macro>

<xf:macro name="navigation_list_entry" arg-navigation="!" arg-children="!" arg-depth="1" arg-defaultNavigationId="">
	<xf:if is="$depth == 1">
		<xf:datarow rowtype="subsection">
			<xf:if is="$navigation.navigation_id == $xf.app.defaultNavigationId">
				<xf:cell>{$navigation.title}</xf:cell>
				<xf:cell />
				<xf:cell />
				<xf:cell />
			<xf:else />
				<xf:cell href="{{ link('navigation/edit', $navigation) }}" hash="{$navigation.navigation_id}">{$navigation.title}</xf:cell>
				<xf:cell class="dataList-cell--min dataList-cell--hint">{$navigation.display_order}</xf:cell>
				<xf:toggle name="enabled[{$navigation.navigation_id}]" selected="$navigation.enabled"
					submit="true"
					tooltip="{{ phrase('enable_disable_x', {'title': $navigation.title}) }}" />
				<xf:delete href="{{ $navigation.canDelete() ? link('navigation/delete', $navigation) : '' }}" />
			</xf:if>
		</xf:datarow>
	<xf:else />
		<xf:datarow>
			<xf:cell href="{{ link('navigation/edit', $navigation) }}"
				hash="{$navigation.navigation_id}"
				class="dataList-cell--d{{ $depth - 1 }}">
				{$navigation.title}
			</xf:cell>
			<xf:cell class="dataList-cell--min dataList-cell--hint">{$navigation.display_order}</xf:cell>
			<xf:toggle name="enabled[{$navigation.navigation_id}]" selected="$navigation.enabled"
				class="dataList-cell--separated" submit="true"
				tooltip="{{ phrase('enable_disable_x', {'title': $navigation.title}) }}" />
			<xf:delete href="{{ $navigation.canDelete() ? link('navigation/delete', $navigation) : '' }}" />
		</xf:datarow>
	</xf:if>
	<xf:if is="$depth == 1 AND $children is empty">
		<xf:datarow rowclass="dataList-row--note dataList-row--noHover">
			<xf:cell colspan="3">{{ phrase('this_section_is_currently_empty') }}</xf:cell>
		</xf:datarow>
	<xf:else />
		<xf:macro name="navigation_list" arg-children="{$children}" arg-depth="{{ $depth + 1 }}" />
	</xf:if>
</xf:macro>