<xf:macro name="simple_category_list"
	arg-selected="0"
	arg-pathToSelected="{{ [] }}"
	arg-children="!"
	arg-extras="!"
	arg-isActive="{{ false }}"
>
	<ol class="categoryList toggleTarget{{ $isActive ? ' is-active' : '' }}">
		<xf:foreach loop="$children" key="$id" value="$child">
			<xf:macro name="simple_category_list_item"
				arg-selected="{$selected}"
				arg-pathToSelected="{$pathToSelected}"
				arg-category="{$child.record}"
				arg-extras="{$extras.{$id}}"
				arg-children="{$child}"
				arg-childExtras="{$extras}"
			/>
		</xf:foreach>
	</ol>
</xf:macro>

<xf:macro name="simple_category_list_item"
	arg-selected="!"
	arg-pathToSelected="{{ [] }}"
	arg-category="!"
	arg-extras="!"
	arg-children="!"
	arg-childExtras="!"
>
	<xf:set var="$isSelected" value="{{ $category.resource_category_id == $selected }}" />
	<xf:set var="$hasPathToSelected" value="{$pathToSelected.{$category.resource_category_id}}" />
	<xf:set var="$isActive" value="{{ $isSelected OR $hasPathToSelected AND $children is not empty }}" />

	<li class="categoryList-item">
		<div class="categoryList-itemRow">
			<xf:if is="$children is not empty">
				<a class="categoryList-toggler{{ $isActive ? ' is-active' : '' }}"
					data-xf-click="toggle" data-target="< :up :next"
					role="button" tabindex="0" aria-label="{{ phrase('toggle_expanded')|for_attr }}"
				></a>
			<xf:else />
				<span class="categoryList-togglerSpacer"></span>
			</xf:if>
			<a href="{{ link('resources/categories', $category) }}" class="categoryList-link{{ $isSelected ? ' is-selected' : '' }}">
				{$category.title}
			</a>
			<span class="categoryList-label">
				<span class="label label--subtle label--smallest">{$extras.resource_count|number_short}</span>
			</span>
		</div>
		<xf:if is="$children is not empty">
			<xf:macro name="simple_category_list"
				arg-selected="{$selected}"
				arg-pathToSelected="{$pathToSelected}"
				arg-children="{$children}"
				arg-extras="{$childExtras}"
				arg-isActive="{$isActive}"
			/>
		</xf:if>
	</li>
</xf:macro>

<xf:macro name="simple_list_block" arg-categoryTree="!" arg-categoryExtras="!" arg-selected="{{ 0 }}">
	<div class="block">
		<div class="block-container">
			<h3 class="block-minorHeader">{{ phrase('categories') }}</h3>
			<div class="block-body">
				<xf:if is="$categoryTree.count()">
					<xf:macro name="simple_category_list"
						arg-children="{$categoryTree}"
						arg-extras="{$categoryExtras}"
						arg-isActive="{{ true }}"
						arg-selected="{$selected}"
						arg-pathToSelected="{{ $selected ? $categoryTree.getPathTo($selected) : [] }}" />
				<xf:else />
					<div class="block-row">{{ phrase('n_a') }}</div>
				</xf:if>
			</div>
		</div>
	</div>
</xf:macro>

<xf:macro name="category"
	arg-category="!"
	arg-extras="!"
	arg-children="!"
	arg-childExtras="!"
	arg-chooseName=""
	arg-bonusInfo="">
	
	<div class="node node--depth2 node--resourceCategory node--resourceCategory{$category.resource_category_id}">
		<div class="node-body">
			<div class="node-main js-nodeMain">
				<xf:if is="$chooseName">
					<xf:checkbox standalone="true">
						<xf:option labelclass="u-pullRight" class="js-chooseItem" name="{$chooseName}[]" value="{$category.resource_category_id}" />
					</xf:checkbox>
				</xf:if>

				<xf:set var="$descriptionDisplay" value="{{ property('nodeListDescriptionDisplay') }}" />
				<h3 class="node-title">
					<a href="{{ link('resources/categories', $category) }}" data-xf-init="{{ $descriptionDisplay == 'tooltip' ? 'element-tooltip' : '' }}" data-shortcut="node-description">{$category.title}</a>
				</h3>
				<xf:if is="$descriptionDisplay != 'none' && $category.description">
					<div class="node-description {{ $descriptionDisplay == 'tooltip' ? 'node-description--tooltip js-nodeDescTooltip' : '' }}">{$category.description|raw}</div>
				</xf:if>

				<div class="node-meta">
					<div class="node-statsMeta">
						<dl class="pairs pairs--inline">
							<dt>{{ phrase('xfrm_resources') }}</dt>
							<dd>{$extras.resource_count|number}</dd>
						</dl>
					</div>
				</div>

				<xf:if is="$bonusInfo is not empty">
					<div class="node-bonus">{$bonusInfo}</div>
				</xf:if>
			</div>

			<div class="node-stats node-stats--single">
				<dl class="pairs pairs--rows">
					<dt>{{ phrase('xfrm_resources') }}</dt>
					<dd>{$extras.resource_count|number}</dd>
				</dl>
			</div>

			<div class="node-extra">
				<xf:if is="{$extras.last_update}">
					<div class="node-extra-row"><a href="{{ link('resources', {'resource_id': $extras.last_resource_id}) }}" class="node-extra-title" title="{$extras.last_resource_title}">{$extras.last_resource_title}</a></div>
					<div class="node-extra-row">
						<xf:date time="{$extras.last_update}" class="node-extra-date" />
					</div>
				<xf:else />
					<span class="node-extra-placeholder">{{ phrase('none') }}</span>
				</xf:if>
			</div>
		</div>
	</div>
	
</xf:macro>